paint-brush
How to Stop an Active Process on a Portby@smpnjn
7,388 reads
7,388 reads

How to Stop an Active Process on a Port

by Johnny SimpsonSeptember 19th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Blockchain is a digital public ledger that stores data securely, making it almost impossible to hack or alter without authorization. Even the ones who are critical of this change cannot deny the potential of using blockchain for other use cases. In this article, we will discuss how this revolutionary technology is changing business processes beyond cryptocurrency. Top 5 use cases include those in supply chain management, land registry, e-voting, and unified communications in the hospitality industry. And there still remains a lot to be explored in the space of innovation, and we will be investing in the community.
featured image - How to Stop an Active Process on a Port
Johnny Simpson HackerNoon profile picture


It is common in Node.js and other languages to run a script on a certain port. Since ports can come in and out of use, it's also common to get the following error:


    Error: listen EADDRINUSE: address already in use :::3000
    at Server.setupListenHandle [as _listen2] (net.js:1318:16)
    at listenInCluster (net.js:1366:12)
    at Server.listen (net.js:1452:7)
    at Function.listen (/application.js:618:24)
    at file:///httpdocs/index.js:149:5
    Emitted 'error' event on Server instance at:
        at emitErrorNT (net.js:1345:8)
        at processTicksAndRejections (internal/process/task_queues.js:80:21) {
        code: 'EADDRINUSE',
        errno: -98,
        syscall: 'listen',
        address: '::',
        port: 3000
    }


This error says that there is currently something running on port 3000, so we can't use it. Fortunately, this is quite easy to fix.


Linux and Mac

To solve this issue on linux or on a mac, you first want to find out the process ID or PID currently running on the port (in our case :3000). To do that, you can use lsof. If you want a way to remember lsof, it is that it means 'list of'.


    lsof -i :3000


This will return processes running on port :3000.</strong> The next step is to kill the processes on that port. Note the PID, and then run the following command, replacing [PID] with your PID:


    kill -15 [PID]


Why -15? -15 refers to the message your computer will send. You should try -15 the first time, as this will lead to an orderly shutdown of port 3000. If that doesn't work, then try:


    kill -9 [PID]


Now there will be nothing running on port :3000. This will also work for any other port you're having issues with, i.e. :8080, :1337, or any other number.

For Windows Users

For any windows users out there, it is slightly different, but I have put this here as it may also prove useful. First off, find what is running at the port you are looking for (i.e. 3000). The PID can be found at the end of the line when you run this process:


    netstat -ano | findstr :3000


<p><strong>Then, similar to linux and mac, kill what is on that port</strong>, replacing PID with the PID for that process from the statement above.</p>

<pre><code class="shell"> taskkill /PID PID /F </code></pre>



Also published here.