Score:0

How do you make nodejs server

in flag
Leo

This is some of the code in nodejs.

const app = express();
const server = app.listen(3000);

app.use(express.static("public"));
console.log("Server is running");
const io = socket(server);

It works on local host. What do you have to do for anyone in the world to be able to connect to it.

Mikael H avatar
br flag
Voting to close as this question is not a good fit for this forum. You'll want to read up on routing, firewalls and Internet security at least.
Score:0
za flag

Caution : opening your machine to the internet implies some security risks. Consider using a dedicated machine (or a raspberry), have backups, limit the time your server is accessible from internet to the minimum until you know how to secure it, learn about security (I like https://tryhackme.com/).

Identify your public address, using for example https://whatismyipaddress.com/ This address is provided by your ISP.

You almost certainly will need to open the port 3000 in the local firewall of your machine (this strongly depends on your OS/distro, but how to do it is already documented somewhere on internet).

Give a try to connect to http://<you.ip.num.bers>:3000

If it doesn't work (most likely), you will need to configure your router/box to do Network Address Translation / Port Address Translation (NAT/PAT) so incoming requests are redirected to your machine.

You will need to identify the ip address of your local machine (ip addr or ipconfig from a terminal).

Connect to your box, and find the section about NAT/PAT configuration. Add a redirection from the port 80 of the WAN interface ("internet") to the ip of your machine and the port you choose (3000 in your example).

You should then be able to connect to your site from anywhere, using your public ip : http://<your.ip.num.bers> There is no need to add :80, it is the default port for http.

It seems that you are at the beginning of a nice journey to sysadmin. You will probably want to learn then about DNS and domain names, reverse-proxy and firewalls.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.