workshopper/learnyounode

Server problems

benleib opened this issue · 3 comments

I am trying to find a way I can launch a server with http. I’ve made localhosts but whenever I make one with a host address the page loads and never stops. My goal is to get a server that I can access from other devices like a chrome book, or normal pc. If you can help I would be grateful.
This is the code

var http = require(‘http’);
var fs = require(‘fs’);
fs.readFile(‘example.html’, function (err, html) {
if (err) {
throw err;
}
http.createServer(function(request, response) {
response.writeHeader(200, {“Content-Type”: “text/html”});
response.write(html);
response.end();
}).listen(8080);
});

Sent with GitHawk

To access the server from devices other than the server machine itself, you need to bind the server at 0.0.0.0 instead of 127.0.0.1.
you should try .listen({ host: "0.0.0.0", port: 8080 })

This issue can be closed as it seems to been resolved.