Skip to main content
D
Node.js
Node.js File System Module

Node.js File System Module

Node.js interacts directly with your computer's files.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

The Node.js File System module lets your JavaScript code read, create, update, and delete files on your actual computer. The browser cannot do this for security reasons, making Node.js incredibly powerful.

Example

Example
1/* this reads a file */
2var fs = require('fs');
3
4fs.readFile('demofile.txt', 'utf8', function(err, data) {
5  if (err) throw err;
6  console.log(data);
7});

Key Points

  • Import the module using `require('fs')`.
  • The `readFile()` method reads file contents.
  • The `writeFile()` method creates new files.
  • The `unlink()` method deletes existing files.

Up Next

Continue your journey with the next topic.

Go to Node HTTP Module