Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
Node.js

Core Module FS (File System)

Use the built-in fs module to read, write, update, and delete files in Node.js.

Core Module FS (File System) — a practical guide to Node.js fs module with clear examples you can reuse in real projects.

Core Module FS (File System) — 10/55 in the Node.js series. Full playlist companion: Node.js complete course on YouTube. Prefer one article? Read the complete Node.js tutorial.

Short description

`fs` is a core Node.js module for filesystem operations. You can use callback, sync, or promise-based APIs.

Write and read a file (callback)

const fs = require('fs');

fs.writeFile('hello.txt', 'Hello Node', (err) => {
  if (err) throw err;
  fs.readFile('hello.txt', 'utf8', (err, data) => {
    if (err) throw err;
    console.log(data);
  });
});

Leave a reply

Your email address will not be published. Required fields are marked *