Node.js ट्यूटोरियल

Node.js होम Node.js परिचय Node.js प्रारंभ करें Node.js मॉड्यूल Node.js HTTP मॉड्यूल Node.js फ़ाइल सिस्टम Node.js URL मॉड्यूल Node.js एनपीएम Node.js घटनाएँ Node.js फ़ाइलें अपलोड करें Node.js ईमेल

Node.js MySQL

MySQL प्रारंभ करें MySQL डेटाबेस बनाएँ MySQL तालिका बनाएँ MySQL सम्मिलित करें MySQL से चुनें MySQL कहाँ MySQL ऑर्डर बाय MySQL हटाएं MySQL ड्रॉप टेबल MySQL अद्यतन MySQL सीमा मायएसक्यूएल जॉइन

Node.js MongoDB

मोंगोडीबी आरंभ करें MongoDB डेटाबेस बनाएँ MongoDB संग्रह बनाएँ मोंगोडीबी डालें मोंगोडीबी खोजें मोंगोडीबी क्वेरी मोंगोडीबी सॉर्ट मोंगोडीबी हटाएं MongoDB ड्रॉप संग्रह मोंगोडीबी अपडेट मोंगोडीबी सीमा मोंगोडीबी शामिल हों

रास्पबेरी पाई

रासपी आरंभ करें रासपी जीपीआईओ परिचय रासपी ब्लिंकिंग एलईडी रासपी एलईडी और पुशबटन रासपी बहने वाली एल ई डी रासपी वेबसाकेट रासपी आरजीबी एलईडी वेबसाकेट रास्पी अवयव

Node.js संदर्भ

अंतर्निहित मॉड्यूल

Node.js इवेंट मॉड्यूल

अंतर्निहित मॉड्यूल


उदाहरण

"चीख" नामक घटना के लिए एक ईवेंट श्रोता बनाएं, फिर ईवेंट को उत्तेजित करें:

var events = require('events');
var eventEmitter = new events.EventEmitter();

eventEmitter.on('scream', function() {
console.log('A scream is detected!');
});
eventEmitter.emit('scream');

परिभाषा और उपयोग

ईवेंट मॉड्यूल ईवेंट के साथ काम करने का एक तरीका प्रदान करता है।

Node.js में, सभी ईवेंट EventEmitter ऑब्जेक्ट का एक उदाहरण हैं


वाक्य - विन्यास

ईवेंट मॉड्यूल को शामिल करने और अपने एप्लिकेशन में EventEmitter बनाने के लिए सिंटैक्स:

var events = require('events');
var eventEmitter = new events.EventEmitter();

EventEmitter गुण और तरीके

Method Description
addListener() Adds the specified listener
defaultMaxListeners Sets the maximum number of listeners allowed for one event. Default is 10
emit() Call all the listeners registered with the specified name
eventNames() Returns an array containing all registered events
getMaxListeners() Returns the maximum number of listeners allowed for one event
listenerCount() Returns the number of listeners with the specified name
listeners() Returns an array of listeners with the specified name
on() Adds the specified listener
once() Adds the specified listener once. When the specified listener has been executed, the listener is removed
prependListener() Adds the specified listener as the first event with the specified name
prependOnceListener() Adds the specified listener as the first event with the specified name, once. When the specified listener has been executed, the listener is removed
removeAllListeners() Removes all listeners with the specified name, or ALL listeners if no name is specified
removeListener() Removes the specified listener with the specified name
setMaxListeners() Sets the maximum number of listeners allowed for one event. Default is 10

अंतर्निहित मॉड्यूल