View example-writable-constructor.js
const { Writable } = require("stream"); | |
const myWritableStream = (data) => { | |
return new Writable({ | |
write(chunk, enc, next) { | |
data.push(chunk); | |
next(); | |
} |
View example-writable.js
const fs = require('fs'); | |
const writableStream = fs.createWriteStream('./files/out.txt'); | |
writableStream.write("This is dummy text1!!"); | |
writableStream.write("\n"); | |
writableStream.write("This is dummy text2!!"); | |
writableStream.write("\n"); | |
writableStream.write("This is dummy text3!!"); | |
writableStream.write("\n"); |
View example-readable-from.js
const { Readable } = require('stream'); | |
const data = [ | |
"This is the stream data 1", | |
"This is the stream data 2", | |
"This is the stream data 3", | |
"This is the stream data 4", | |
"This is the stream data 5" | |
]; |
View example-readable-constructor.js
const { Readable } = require('stream'); | |
const myReadbleStream = () => { | |
const data = [ | |
"This is the stream data 1", | |
"This is the stream data 2", | |
"This is the stream data 3", | |
"This is the stream data 4", | |
"This is the stream data 5" | |
]; |
View example-readable.js
const fs = require('fs') | |
const readableStream = fs.createReadStream('./files/file1.txt'); | |
readableStream.on('data', (data) => { | |
console.log('Received Data ', data.toString()); | |
}); | |
readableStream.on('end', () => { | |
console.log('End of file reached!!!'); |
View file1.js
This data comimg from the file1 This data comimg from the file1 This data comimg from the file1 This data comimg from the file1 | |
This data comimg from the file1 This data comimg from the file1 This data comimg from the file1 This data comimg from the file1 | |
This data comimg from the file1 This data comimg from the file1 This data comimg from the file1 This data comimg from the file1 | |
This data comimg from the file1 This data comimg from the file1 This data comimg from the file1 This data comimg from the file1 | |
This data comimg from the file1 This data comimg from the file1 This data comimg from the file1 This data comimg from the file1 | |
This data comimg from the file1 This data comimg from the file1 This data comimg from the file1 This data comimg from the file1 | |
This data comimg from the file1 This data comimg from the file1 This data comimg from the file1 This data comimg from the file1 | |
This data comimg from the file1 This data comimg from the file1 This data comimg from the file1 This data comimg from the file1 |
View simple-http-example.js
const http = require('http'); | |
const server = http.createServer((req, res) => { | |
// `req` is an http.IncomingMessage, which is a readable stream. | |
// `res` is an http.ServerResponse, which is a writable stream. | |
let body = ''; | |
// Get the data as utf8 strings. | |
// If an encoding is not set, Buffer objects will be received. | |
req.setEncoding('utf8'); |
View async-await-parallel.js
var rp = require('request-promise'); | |
function printUsers(users) { | |
console.log('Users Length:::', users.length); | |
console.log(users); | |
} | |
function printEmails(emails) { |
View async-await-series.js
var rp = require('request-promise'); | |
function printUsers(users) { | |
console.log('Users Length:::', users.length); | |
console.log(users); | |
} | |
function printEmails(emails) { |
View async-await-simple.js
var rp = require('request-promise'); | |
async function fetchData() { | |
const data = await rp('http://localhost:3070/users'); | |
console.log(JSON.parse(data)); | |
} | |
fetchData().catch(err => console.log(err)); |
NewerOlder