My Blog List

Thursday, August 28, 2014

read file in folder and write in browser in nodejs

this is a sample http server and read file and print in brwoser
when you call

var http = require("http");
var fs = require('fs');
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
var text= fs.readFileSync('textfile.txt', 'utf-8');

response.write(text);  response.end();

No comments:

Post a Comment