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
http://localhost:8888/

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();
}).listen(8888);

No comments:

Post a Comment