Tutorial by Examples

I/O in node is asynchronous, so interacting with the disk and network involves passing callbacks to functions. You might be tempted to write code that serves up a file from disk like this: var http = require('http'); var fs = require('fs'); var server = http.createServer(function (req, res) { ...
Readable streams can be "piped," or connected, to writable streams. This makes data flow from the source stream to the destination stream without much effort. var fs = require('fs') var readable = fs.createReadStream('file1.txt') var writable = fs.createWriteStream('file2.txt') rea...
We will see stream objects being returned by modules like fs etc but what if we want to create our own streamable object. To create Stream object we need to use the stream module provided by NodeJs var fs = require("fs"); var stream = require("stream").Writable; ...
Lets examine the following two examples for reading a file's contents: The first one, which uses an async method for reading a file, and providing a callback function which is called once the file is fully read into the memory: fs.readFile(`${__dirname}/utils.js`, (err, data) => { if (err) {...

Page 1 of 1