Publish Node.JS server on the internet

Your app should listen on other ip address, example

app.listen(3000,'0.0.0.0');

or just

app.listen(3000);

Then you must open port forwarding in your modem. Like this http://www.dlink.com/uk/en/support/faq/routers/wireless-routers/dkt-series/how-do-i-open-up-ports-to-my-computer-port-forwarding-on-this-router

Finally you can see your app at ip address in here https://whatismyipaddress.com/


const http = require("http");
const hostname = '0.0.0.0';
const port = 80;

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

using 0.0.0.0 will start listing to the public internet I have tested it.

I have experienced the cases that the ISP given router is intercepting default 80 and 443 ports. Even though the ports are opened. So better check server first using a port like 8080 etc.

And also configure port forwarding to a static local address (ipconfig /all assumed your host is windows) then assigned that IP address to your host using host's MAC address.

for a better experience, if you don't have a static IP, use noip.com dynamic domain names to access your server at any time (without knowing IP address).


You are most likely behind a router so your public IP is not available anywhere but on the router itself. What you need to do is listening on your private IP (usually somehing in the 192.168.* range) and setup a port forward on your router.

In case you are on Linux you'll also want to use a port >1024 instead of 80 so you don't have to run node as root. When setting up the port forwarding you can simply forward port 80 to whatever port your node server is running on.