Node.js ကျူတိုရီရယ်

Node.js ပင်မစာမျက်နှာ Node.js နိဒါန်း Node.js ကို စတင်လိုက်ပါ။ Node.js မော်ဂျူးများ Node.js HTTP မော်ဂျူး Node.js ဖိုင်စနစ် Node.js URL မော်ဂျူး Node.js NPM Node.js ပွဲများ Node.js ဖိုင်များ အပ်လုဒ်လုပ်ခြင်း။ Node.js အီးမေးလ်

Node.js MySQL

MySQL စတင်လိုက်ပါ။ MySQL ဒေတာဘေ့စ်ဖန်တီးပါ။ MySQL ဇယားဖန်တီးပါ။ MySQL ထဲသို့ ထည့်သွင်းပါ။ MySQL မှ ရွေးချယ်ပါ။ MySQL ဘယ်မှာလဲ။ MySQL Order By MySQL ကိုဖျက်ပါ။ MySQL Drop Table MySQL အပ်ဒိတ် MySQL ကန့်သတ်ချက် MySQL Join

Node.js MongoDB

MongoDB စတင်လိုက်ပါ။ MongoDB ဒေတာဘေ့စ်ဖန်တီးပါ။ MongoDB သည် Collection ကိုဖန်တီးပါ။ MongoDB ထည့်သွင်းပါ။ MongoDB ကိုရှာပါ။ MongoDB မေးခွန်း MongoDB အမျိုးအစား MongoDB ကိုဖျက်ပါ။ MongoDB Drop Collection MongoDB အပ်ဒိတ် MongoDB ကန့်သတ်ချက် MongoDB Join

Raspberry Pi

RasPi စတင်လိုက်ပါ။ RasPi GPIO နိဒါန်း RasPi မှိတ်တုတ်မှိတ်တုတ် LED RasPi LED နှင့် ခလုတ်နှိပ်ပါ။ RasPi စီးဆင်းနေသော LED များ RasPi WebSocket RasPi RGB LED WebSocket RasPi အစိတ်အပိုင်းများ

Node.js အ ကိုး အကား

Built-in Modules များ

Node.js Events Module

❮ Built-in Modules


ဥပမာ

"scream" ဟုခေါ်သော ဖြစ်ရပ်အတွက် ပွဲနားထောင်သူကို ဖန်တီးပြီး ပွဲကို နှိုးဆော်လိုက်ပါ-

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

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

အဓိပ္ပါယ်နှင့် အသုံးပြုမှု

Events module သည် ဖြစ်ရပ်များနှင့် အလုပ်လုပ်ပုံအား ပံ့ပိုးပေးပါသည်။

Node.js တွင်၊ ဖြစ်ရပ်များအားလုံးသည် EventEmitter အရာဝတ္ထု၏ ဥပမာတစ်ခုဖြစ်သည်။


အထားအသို

Events module အပါအဝင် သင့်အပလီကေးရှင်းတွင် EventEmitter ဖန်တီးခြင်းအတွက် syntax သည်-

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

EventEmitter Properties နှင့် Methods

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

❮ Built-in Modules