codegurukool.com · Free coding tutorials & online compiler

Home › Node.js Tutorial › Node.js file system

Node.js file system

Read and write files.

The fs module reads and writes files. fs.writeFileSync and fs.readFileSync block until done; the promise version fs.promises does not.

Example code

const fs = require("fs");
const path = require("path");
const p = path.join(require("os").tmpdir(), "note.txt");
fs.writeFileSync(p, "Saved text");
console.log(fs.readFileSync(p, "utf8"));

Run this code in the online editor

← Node.js built-in modulesNode.js events →