Created
August 20, 2017 21:24
-
-
Save natmegs/8c55b8373c88a2103c21fef4bb0546e6 to your computer and use it in GitHub Desktop.
Node Server responding with HTML (sync)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
res.end(html); | |
}).listen(1337, '127.0.0.1'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment