Hello to all, welcome to therichpost.com. 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:
https://nodejs.org
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'}); res.write(data); res.end(); }); }).listen(8080);
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:
http://localhost:8080/
If you have any query related to this post, then please comment below or ask question.
Thank you,
Happy Coding,
Therichpost
Simple and easy
Thank you jasmeen..