Node.js File System Module

Node.js File System(fs) Module

Node.js File System Module is used for file handing which supports Read files, Create files, Update files, Delete files and Rename files.

We can include file system module as below in application

var fs = require('fs');

Read files

fs.readFile() method is used to read file.

Example : 

const http = require('http');

const fs = require('fs');

const port = 5555;

const server = http.createServer(function (req, res) {

  fs.readFile('aryatechno.html', function(err, data) {
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.end('Welcome to aryatechno Node.js tutorials!');


server.listen(port function() {

    console.log(`Server running at port ${port}:${port}`)


Create files

Below Node.js module methods are used to create new files.



Update Files

Below Node.js module methods are used to update contents into file.

  • fs.appendFile()
  • fs.writeFile()


Delete Files

Node.js module methods fs.unlink() is used to delete file.

Rename Files

fs.rename() method is used to rename file.

Upload Files

formidable module is used to upload file.




Leave a Reply

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