Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

event in node js

const EventEmitter = require('events')
const myEmitter = new EventEmitter();
myEmitter.emit('newSale') //give name 
//setup listener
myEmitter.on("newSale", ()=> {console.log("There was a new sale!")})
myEmitter.emit("newSale")
Comment

make event nodejs

const events = require('events');

let emitter = new events.EventEmitter();

emitter.on('newEvent', (message)=>{
	
	console.log(`Message : ${message}`);
});

emitter.emit('newEvent', 'Hello guys, this is CodezUp');
Comment

nodejs event

const EventEmitter = require('events');

class MyEmitter extends EventEmitter {}

const myEmitter = new MyEmitter();
myEmitter.on('event', () => {
  console.log('an event occurred!');
});
myEmitter.emit('event');
Comment

event node.js

import { EventEmitter } from "node:events";
/**
 * add "type":"module" in package.json
 */

class MyEmitter extends EventEmitter {}

const myEvent = new MyEmitter();

myEvent.on("event", () => {
  console.log("an event occurred!");
});

myEvent.emit("event");
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript validate password 
Javascript :: placeholder value javascript 
Javascript :: document print from html javascript 
Javascript :: getboundingclientrect() javascript 
Javascript :: javascript delete second last element of array 
Javascript :: jquery find by data attribute 
Javascript :: videojs cdn 
Javascript :: how to make a textarea unwritable in react native 
Javascript :: current date minus days javascript 
Javascript :: how to pass sequelize transaction to association helper method 
Javascript :: how many days old am i 
Javascript :: how to make a vowel counter in javascript 
Javascript :: get first day of the week of a given date javascript js 
Javascript :: js find longest word in string function 
Javascript :: js window.confirm 
Javascript :: js get id value 
Javascript :: javascript remove object property 
Javascript :: leaflet center map 
Javascript :: vue 3 global variable 
Javascript :: how to get an absolute in js 
Javascript :: adding border in react native 
Javascript :: react check if mobile or desktop 
Javascript :: history.push with params 
Javascript :: json.stringify formatting 
Javascript :: reduce parameters 
Javascript :: jquery find children not working 
Javascript :: jquery get data attribute 
Javascript :: react native responsive font 
Javascript :: angular filter ngfor 
Javascript :: Remove duplication from array in javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =