When you work with NodeJS and micro-service architecture by the end of the day there are a number of ports that you start using.

To check which port is already in use, use the following command.

For Linux

netstat -lnp | grep node
  • -l: Show only listening ports.
  • -n: Show numerical addresses instead of resolving hostnames.
  • -p: show type of port (grep works on this)
ss -tuln
  • -t: Show TCP ports.
  • -u: Show UDP ports.
  • -l: Show only listening ports.
  • -n: Show numerical addresses instead of resolving hostnames.
lsof -i -n -P | grep node
  • i: Specifies that you're interested in network-related information, specifically open network connections and listening sockets.
  • -n: Prevents lsof from attempting to resolve IP addresses to hostnames. Shows numerical IP addresses instead.
  • -P: Prevents lsof from resolving port numbers to service names. Shows numerical port numbers instead.

For Mac

lsof -i -n -P | grep node
  • i: Specifies that you're interested in network-related information, specifically open network connections and listening sockets.
  • -n: Prevents lsof from attempting to resolve IP addresses to hostnames. Shows numerical IP addresses instead.
  • -P: Prevents lsof from resolving port numbers to service names. Shows numerical port numbers instead.

Additionally, you can use graphical tools like lsof and network monitoring tools like nmap for more advanced analysis of open ports and network connections.