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 Stream Module

❮ Built-in Modules


ဥပမာ

ရေးနိုင်သော လမ်းကြောင်းသို့ ရေးပါ-

var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.write('Hello World!');
  res.end();
}).listen(8080);

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

Stream module သည် streaming data ကို ကိုင်တွယ်သည့်နည်းလမ်းကို ပံ့ပိုးပေးပါသည်။

stream အမျိုးအစား နှစ်မျိုးရှိသည်- readable နှင့် writeable.

readable stream ၏ ဥပမာတစ်ခုသည် http.createServer() method ဖြင့် လုပ်ဆောင်သောအခါ သင်ရရှိသည့် တုံ့ပြန်မှု အရာဝတ္ထုဖြစ်သည်။

စာရေး နိုင်သော stream ၏ ဥပမာတစ်ခုသည် http.createServer() method ဖြင့် လုပ်ဆောင်သောအခါ သင်ရရှိသည့် တောင်းဆိုချက် အရာဝတ္ထုဖြစ်သည်။


အထားအသို

အချို့သောနည်းလမ်းများသည် http.createServer() ကဲ့သို့ readable/writable stream object ကို ပြန်ပို့ပေးပြီး ထိုသို့ဖြစ်ပါက၊ သင်သည် stream module ကို ထည့်သွင်းရန် မလိုအပ်ပါ။

မဟုတ်ပါက၊ သင့်အပလီကေးရှင်းတွင် တိုက်ရိုက်ထုတ်လွှင့်မှု မော်ဂျူး အပါအဝင် အထားအသို-

var stream = require('stream');

Readable Stream Properties နှင့် Methods

Method Description
isPaused() Returns true if the state of  the readable stream is paused, otherwise false
pause() Pauses the readable stream
pipe() Turns the readable stream into the specified writable stream
read() Returns a specified part of the readable stream
resume() Resumes a paused stream
setEncoding() Sets the character encoding of the readable stream
unpipe() Stops turning a readable stream into a writable stream, caused by the pipe() method
unshift() Pushes some specified data back into the internal buffer
wrap() Helps reading streams made by older Node.js versions

Writable Stream Properties နှင့် Methods

Method Description
cork() Stops the writable stream and all written data will be buffered in memory
end() Ends the writable stream
setDefaultEncoding() Sets the encoding for the writable stream
uncork() Flushes all data that has been buffered since the cork() method was called
write() Writes data to the stream

❮ Built-in Modules