Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Node Server responding with HTML (sync)
var http = require('http');
var fs = require('fs');
http.createServer(function(req, res) {
// Specify html content type
res.writeHead(200, { 'Content-Type': 'text/html' });
// Read contents of index.htm file synchronously,
// Saved as string in var html
var html = fs.readFileSync(__dirname + '/index.htm');
// Send contents of index.htm file as body of response
}).listen(1337, '');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment