Menu BAR

FEEL FREE TO ASK ANY PROGRAM and please mention any error if you find it

13 Nov 2022

Node JS program to create a new file

 3) Create a new text file from Node.js 

var fs = require ('fs');  // include pre-built node file stream module
var data = "Creating a new file";


fs.writeFile('newFile.txt', data, function (err){
    if (err) throw err;
    console.log (" File created successfully"};
});


Run the program in the terminal:
$ node createNewFile.js
File created successfully

No comments:

Post a Comment