Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

stream in node.js

streams is process(read and write) data piece(chunks) without completing the
whole read or write operation, and therefore without keeping all the data in 
memory.
There are four types of streams => readable streams, writable streams, duplex
and transform streams.
Comment

nodejs create stream

const { Readable } = require("stream")

const readable = Readable.from(["input string"])

readable.on("data", (chunk) => {
  console.log(chunk) // will be called once with `"input string"`
})
Comment

nodejs stream

const stream = require('stream')
const fs = require('fs')

const html = "<h1> Hello Wordl </h1>

// read file from string and write file
const stream = new Stream()
stream.pipe = function (dest) {
  dest.write(html)
  return dest
}
stream.pipe(createWriteStream(resolve(process.cwd(), 'index.html'), 'utf8'))

// read file from directory and write file
fs.createReadStream('testing.html')
 .pipe(createWriteStream(resolve(process.cwd(), 'index.html'), 'utf8'))
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to send js array from ajax 
Javascript :: jest mock method by name 
Javascript :: double logical not javascript 
Javascript :: js object.entries with sort 
Javascript :: how to assign variables in javascript 
Javascript :: javascript convert minus to plus 
Javascript :: chrome block javascript alert 
Javascript :: sanitize html in javascript 
Javascript :: tables javascript 
Javascript :: destructuring an object js 
Javascript :: javascript how to open a file 
Javascript :: function to count words in string 
Javascript :: threemeshphonematerial url image three js 
Javascript :: angular property value does not exist on type Event 
Javascript :: jquery add 
Javascript :: ejs render 
Javascript :: how to push mutual array elements in an array nested loop javascript 
Javascript :: js outputting data 
Javascript :: array with object same keys 
Javascript :: enable swipe using javascript 
Javascript :: redux toolkit remove from array 
Javascript :: javascript set cookie 
Javascript :: console.log() Print a Sentence 
Javascript :: remove duplicates javascript 
Javascript :: use of split and join 
Javascript :: js reduce example 
Javascript :: building a linked list javascript 
Javascript :: set array length js 
Javascript :: math js 
Javascript :: javascript timestamp 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =