'starting a node.js page on localhost - the site can't be reached

I'm on Chrome / Windows 7 and trying to make my first node.js steps using this tutorial:

https://www.w3schools.com/nodejs/nodejs_get_started.asp

So myfirst.js is:

var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.end('Hello World!');
}).listen(8080);

Going on http://localhost:8080/ I'm getting the error:

This site can’t be reached localhost refused to connect.
Try:

Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED

Firewall is completely off.

Any help?



Solution 1:[1]

check your firewall you must edit in firewall system Node.js as public enter image description here

enter image description here

Solution 2:[2]

server.listen(port, hostname, () => { console.log(Server running at: http://${hostname}:${port}/); });

port=8080 hostname=127.0.0.1 or 192.168.1.x(your ip)

maybe 8080 is use by other software

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pedram Ghaneipour
Solution 2 Pedram Ghaneipour