One liner to create a Node.js HTTP server:
Print out the process ID instead:
This is useful with the worker process when implementing the cluster module.
This is a bare minimal HTTP server:
port number is evaluated to be falsy, such as
undefined or an empty string, a random port will be assigned.
Begin accepting connections on the specified
hostname. If the
hostnameis omitted, the server will accept connections on any IPv6 address (::) when IPv6 is available, or any IPv4 address (0.0.0.0) otherwise. A port value of zero will assign a random port. - https://iojs.org/api/http.html#http_server_listen_port_hostname_backlog_callback
We can use command line tool such as
netstat to find out the port number:
However, it will be very convenient without relying on external tools.
Luckily, we can find out the port number by using the
The result will be similar to:
Furthermore, it works with all popular libraries that create an