Skip to content

Instantly share code, notes, and snippets.

@jamesgeorge007
Last active March 8, 2018 13:24
Show Gist options
  • Save jamesgeorge007/498b126a63ec6d5709ae111bf30d36c5 to your computer and use it in GitHub Desktop.
Save jamesgeorge007/498b126a63ec6d5709ae111bf30d36c5 to your computer and use it in GitHub Desktop.
Web page rendering sample in Node JS using the fs module with which an html file is being rendered in the browser.
<html>
<head/>
<body>
<h1> This is a webpage rendered by Node JS. </h1>
</body>
</html>
var http = require('http');
var fs = require('fs');
http.createServer(function(request, response)
{
response.writeHead(200, {'Context-Type':'text/html'});
fs.readFile('./index.html', null, function(error, data)
{
if(error)
{
response.writeHead(404);
response.write("Page not found!");
}
else
{
response.write(data);
}
response.end();
});
}
).listen(8000);
console.log("Listening on port 8000.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment