Writing a file synchronously using node.js


Overview

Writing a file synchronously using fs.writeFileSync method of fs module of node.js

Code


													
//Name of the file : writefile-sync.js
//Writing a File synchronously using nodejs
var fs = require('fs');

var content = "We are writing this file synchronously using node.js";

fs.writeFileSync('content.txt', content);
console.log("File Written Successfully");
													
												

Run

  • Now run the snippet using the following command :
    													
    >node writefile-sync.js
    File Written Successfully
    													
    												

Summary