简体   繁体   中英

Why does the nodeJS 'Hello World' example not work?

pasted a simple Hello World example from here to ubuntu machine. But it does not work. I get the output from console.log(), but navigate a webbrowser (firefox) to 127.0.0.1:8081 just outputs

'Problem landing page' The connection was reset The connection to the server was reset while the page was loading.

var http = require("http");

http.createServer(function (request, response) {

   response.writeHead(200, {'Content-Type': 'text/plain'});

   response.end('Hello World\n');
}).listen(8081);

console.log('Server running at http://127.0.0.1:8081/');

Whats wrong with it?

Make sure to:

  • -run npm uninstall http
  • -run init -y
  • -run npm i
  • -run npm http

If you have done already all this, make sure to go use Google, and not Bing Explorer, or Firefox

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM