Last active
March 8, 2018 13:24
-
-
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.
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
<html> | |
<head/> | |
<body> | |
<h1> This is a webpage rendered by Node JS. </h1> | |
</body> | |
</html> |
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(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