🎓 Get Full Quality Study Materials & Lab Manuals — Follow our blog using the button below!  |  📺 Subscribe our YouTube Channel "Lectures by Ravula Govardhan" for Programming Contents!  | 
● NEW Experiment 1 to 13 Full Stack Development Lab Programs available Read it here →
“à°ˆ à°°ోà°œు à°¨ేà°°్à°šుà°•ుà°¨్à°¨ à°šిà°¨్à°¨ à°µిà°·à°¯ం, à°°ేపటి à°ªెà°¦్à°¦ à°µిజయాà°¨ిà°•ి à°ªుà°¨ాà°¦ి.”

File Management and Streaming in Node.js | Node.js Lab Program with Source Code and Output

Experiment · Node.js Lab

File Management and Streaming using Node.js

Aim

Implement file management and streaming using Node.js.

Explanation

  • fs is used to work with files in Node.js.
  • writeFileSync() creates data.txt and writes text into it.
  • console.log() displays "File created".
  • createReadStream() reads the file using streaming.
  • The data event reads the file data in chunks.
  • The end event shows that reading is completed.

Source Code

src/App.js
const fs = require("fs");

fs.writeFileSync("data.txt", "Hello Node.js!");
console.log("File created.");

const stream = fs.createReadStream("data.txt", "utf8");

stream.on("data", chunk => console.log("Data:", chunk));
stream.on("end", () => console.log("Reading completed."));
01 Execute
Terminal
node app.js

Output

File created.
Data: Hello Students!
We are learning Node.js.
Reading completed.

Result: The Node.js program has accomplished the task of file creation and using a stream to read its contents. Hence, file management and streaming processes have been carried out successfully.

Node.js File Management File Streaming JavaScript Node.js Lab

0 Ravula Kartheek:

Post a Comment