Node.js Create a New File

In NodeJS, to create a new, you can use a quick and simple method in the “fs”¬†module.

How to Create a new File in Node.js

//load the fs module
var fs = require('fs');

fs.writeFile('/path/file.txt', "fileData", function (err) {
  if(!err) {
    console.log("file successfully saved.");
  } else {
    console.log("error", err);
  }
});