Node.js http serve file content

Description

Node.js http serve file content

var http = require('http');
var fs = require('fs'); 

var hello = fs.readFileSync('HelloWorld1.html'); 
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.end(hello); //from   ww w. ja va2s.c o m
}).listen(8080, '127.0.0.1');

console.log('http://127.0.0.1:8080/');



PreviousNext

Related