Port is Already in Use Error and How to fix it with NPX

Rabi Siddique
2 min readMay 8, 2022

Ever encountered the port is already in useerror?

Network services tend to make use of IP addresses along with TCP ports to create a unique address for the service you’re trying to use. This is done to ensure only one port is being used for a single process, at a given time.

We tend to get the port is already in useerror when some other process is making use of the port we’re trying to make use of. Consequently, it leads to the aborting of the process we’re trying to initiate.

We have two options here. Either we can start our desired process on a different port or we can determine which process is using the port we’re trying to make use of and stop that process. In some cases, we might even need to restart our device.

However, there’s a much easier way to do it, using 𝐧𝐩𝐱.

The syntax of availing of the intended port is as follows:
𝐧𝐩𝐱 𝐤𝐢𝐥𝐥-𝐩𝐨𝐫𝐭 𝐧𝐮𝐦𝐛𝐞𝐫𝐎𝐟𝐓𝐡𝐞𝐏𝐨𝐫𝐭

For example,
𝐧𝐩𝐱 𝐤𝐢𝐥𝐥-𝐩𝐨𝐫𝐭 𝟖𝟎𝟖𝟎 ==> Results in the killing of the process using port 8080. And now we can initiate our desired process on port 8080.

We can free up multiple ports using the 𝐧𝐩𝐱 𝐤𝐢𝐥𝐥-𝐩𝐨𝐫𝐭 command as follows:
𝐧𝐩𝐱 𝐤𝐢𝐥𝐥-𝐩𝐨𝐫𝐭 𝟒𝟎𝟎𝟎 𝟓𝟎𝟎𝟎 𝟖𝟎𝟖𝟎 ==> Results in the killing of the processes using the ports 4000, 5000, and 8080.

--

--

Rabi Siddique

A passionate Software Engineer who intends to be the best and nothing less.