Anniee Anniee - 17 days ago 5
Node.js Question

Link HTML page to NodeJS Server - wont load as localhost?

I am trying to create a nodejs server - I have previously managed to - without an HTML page. However, for this task I need to have it direct to RedGreenBlue.html. I am really struggling and any advice would be greatly appreciated.

Many Thanks

JS Server

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

fs.readFile('./RedGreenBlue.html', function (err, html) {
if (err) {
throw err;
http.createServer(function(request, response) {
response.writeHeader(200, {"Content-Type": "text/html"});


You don't see anything, because there is no output to stdout in your application (e.g. no console.log). Therefore, when you execute the app via node ServerRedBlueGreen.js, it reads the defined file and opens the port 8000. You can communicate with the application through this port via HTTP.

So open up another shell and execute curl http://localhost:8000 and you should see a response. You could open the URL in your browser as well.

Hope I could help in some way :)