Saturday, October 23, 2021

Node Js – Reading File Simple Example

Node Js - Reading File Simple Example

Hello to all, welcome to In this post, we will do, Node Js – Reading File Simple Example.

Nodejs is an open-source server environment which runs Javascript on the server.

I was just practicing node js and I liked it very much and seems interesting so that is why, I am sharing code on my blog.

I am sharing the code for to read file with nodejs and for this, we will file-system module in our nodejs application.

Very first, we need to install nodejs into our system and here is the link:


Here is the working and tested code and you need to add this into your js file:


1. You need add the below code into your YourFileName.js file:

var http = require('http');
var fs = require('fs');
http.createServer(function (req, res) {
  fs.readFile('applications.html', function(err, data) {
    res.writeHead(200, {'Content-Type': 'text/html'});


2. After it, you need to run below command into your terminal to execute js file:

 node YourFileName.js


3. After it, run below url into your browser:


If you have any query related to this post, then please comment below or ask question.

Thank you,

Happy Coding,


Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, Angular 8, Angular 9, Angular 10, Angular 11, Angular12, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.