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);

Comments

Popular posts from this blog

Project euler 169 found clue

Floyd-Warshall's algorithm