Hostname in socket server

I'm using the nodejs library:

import net from 'net'

When creating a server via:

net.createServer

Then I can make the server listen using the next procedure:

server.listen({host: 'localhost', port: 8000, exclusive: true}, () => etc..)

My question is why do I need to specify a host for the server? I mean, I should not always be serving on the server/ip where the service is placed? When I deploy a service in spring or nginx I don't have to specify the actual host since it's assumed what host should use. Isn't it right?

Upvotes: 0

Views: 264

Answers (1)

Tyler2P
Tyler2P

Reputation: 2370

To answer your question, you do not need to specify a host when deploying your server. It is an optional dependency for people who may be using a VPN and have 2 different IP addresses.
The following code is all you need to deploy your web server.

server.listen(port, function() {
    // Do something
});

Upvotes: 1

Related Questions