<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: member_5f2e5c01</title>
    <description>The latest articles on DEV Community by member_5f2e5c01 (@member_5f2e5c01).</description>
    <link>https://dev.to/member_5f2e5c01</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4252703%2F28c47ec0-71e8-476b-b412-9c230c72c410.png</url>
      <title>DEV Community: member_5f2e5c01</title>
      <link>https://dev.to/member_5f2e5c01</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/member_5f2e5c01"/>
    <language>en</language>
    <item>
      <title>EADDRINUSE address already in use: 4 safe fixes</title>
      <dc:creator>member_5f2e5c01</dc:creator>
      <pubDate>Wed, 18 Nov 2026 23:51:10 +0000</pubDate>
      <link>https://dev.to/member_5f2e5c01/eaddrinuse-address-already-in-use-4-safe-fixes-9c8</link>
      <guid>https://dev.to/member_5f2e5c01/eaddrinuse-address-already-in-use-4-safe-fixes-9c8</guid>
      <description>&lt;p&gt;&lt;code&gt;Error: listen EADDRINUSE: address already in use&lt;/code&gt; means your Node.js server tried to open a port that another program is already using. Most of the time that "other program" is an old copy of your own server that never stopped. This guide shows how to find it on Windows, stop it safely, and make your app handle a busy port on its own. Every command below was run on Windows 11 with Node.js 26.&lt;/p&gt;

&lt;h2&gt;
  
  
  What does EADDRINUSE address already in use mean?
&lt;/h2&gt;

&lt;p&gt;A port is a numbered door on your computer, like &lt;code&gt;3000&lt;/code&gt;. Only one program can listen on a port at a time. When your server calls &lt;code&gt;listen(3000)&lt;/code&gt; and something already owns port 3000, Node.js throws this error and your app stops:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node:events:505
    throw er; // Unhandled 'error' event
    ^

Error: listen EADDRINUSE: address already in use :::3000
    at Server.setupListenHandle [as _listen2] (node:net:2390:16)
    ...
  code: 'EADDRINUSE',
  errno: -4091,
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;:::3000&lt;/code&gt; is the IPv6 way of writing "every address, port 3000". The Node.js docs call EADDRINUSE "one of the most common errors raised when listening" (&lt;a href="https://nodejs.org/api/net.html#serverlisten" rel="noopener noreferrer"&gt;Node.js net docs&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Why does it happen?
&lt;/h2&gt;

&lt;p&gt;The usual causes, from most to least common:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;An old server is still running.&lt;/strong&gt; You closed the editor or the terminal tab, but the Node process kept going in the background.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You started the app twice.&lt;/strong&gt; For example, &lt;code&gt;npm run dev&lt;/code&gt; in two terminals.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Another app uses the same port.&lt;/strong&gt; Many tools default to &lt;code&gt;3000&lt;/code&gt;, &lt;code&gt;5173&lt;/code&gt;, &lt;code&gt;8080&lt;/code&gt; or &lt;code&gt;5000&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A crashed watcher left a process behind.&lt;/strong&gt; Tools that restart your server on save can occasionally leave an old copy running.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Fix 1: Find and stop the process on Windows
&lt;/h2&gt;

&lt;p&gt;First find which process owns the port. In Command Prompt or PowerShell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;netstat&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;ano&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;findstr&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The last column is the process ID (PID):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  TCP    0.0.0.0:3000      0.0.0.0:0      LISTENING       17596
  TCP    [::]:3000         [::]:0         LISTENING       17596
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check what that PID is before you stop it, so you don't close something important:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;Process&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Id&lt;/span&gt; &lt;span class="mi"&gt;17596&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If it's &lt;code&gt;node&lt;/code&gt;, stop it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;taskkill&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="no"&gt;PID&lt;/span&gt; &lt;span class="mi"&gt;17596&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="no"&gt;F&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Windows replies &lt;code&gt;SUCCESS: The process with PID 17596 has been terminated.&lt;/code&gt; Now start your server again.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Commands like &lt;code&gt;taskkill /IM node.exe /F&lt;/code&gt; stop &lt;strong&gt;all&lt;/strong&gt; Node programs, including other projects, your editor's language tools and build watchers. Stop the one PID that holds the port.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  The PowerShell one-liner
&lt;/h3&gt;

&lt;p&gt;PowerShell can find and stop it in one go. This only targets the process listening on that port:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="nc"&gt;Stop&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;Process&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Id&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;NetTCPConnection&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;LocalPort&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;State&lt;/span&gt; &lt;span class="nc"&gt;Listen&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OwningProcess&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Force&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  On macOS or Linux
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;lsof&lt;/code&gt; to list the process on the port, then stop it by PID (&lt;a href="https://man7.org/linux/man-pages/man8/lsof.8.html" rel="noopener noreferrer"&gt;lsof manual&lt;/a&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lsof -i :3000
&lt;span class="nb"&gt;kill&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;PID&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Fix 2: Use a different port
&lt;/h2&gt;

&lt;p&gt;If you need both programs running, give your app another port. Read it from the &lt;code&gt;PORT&lt;/code&gt; environment variable so you can change it without editing code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;PORT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`Listening on http://localhost:${PORT}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then start it on a free port. In PowerShell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;PORT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3001&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;js&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In bash (macOS, Linux, Git Bash):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;PORT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3001 node server.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Fix 3: Handle EADDRINUSE in your code
&lt;/h2&gt;

&lt;p&gt;By default the error crashes your app with an "Unhandled 'error' event". Listen for the server's &lt;code&gt;error&lt;/code&gt; event instead, and try the next port. This is a tested version of the approach in the &lt;a href="https://nodejs.org/api/net.html#serverlisten" rel="noopener noreferrer"&gt;Node.js docs&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'node:http'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createServer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ok'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'error'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'EADDRINUSE'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`Port ${port} is busy, trying ${port + 1}...`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;port&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'listening'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`Listening on http://localhost:${port}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With port 3000 busy, it prints:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Port 3000 is busy, trying 3001...
Listening on http://localhost:3001
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use this for local development. In production, a fixed port is usually better, so a busy port should stop the app and show up in your logs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fix 4: Stop it from coming back
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Stop servers with &lt;code&gt;Ctrl+C&lt;/code&gt; in the terminal before you close it.&lt;/li&gt;
&lt;li&gt;Run your dev server in one terminal only. If your editor has a "Run" button, don't also start it by hand.&lt;/li&gt;
&lt;li&gt;If a file watcher keeps leaving copies behind, update it, or stop it with &lt;code&gt;Ctrl+C&lt;/code&gt; before you close the window.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Still seeing EADDRINUSE address already in use?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;netstat shows nothing, but the error continues:&lt;/strong&gt; your app may be calling &lt;code&gt;listen()&lt;/code&gt; twice, for example once in &lt;code&gt;app.js&lt;/code&gt; and again in a test file. Search your code for &lt;code&gt;.listen(&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The PID belongs to &lt;code&gt;System&lt;/code&gt; or a service:&lt;/strong&gt; a Windows service owns that port. Pick another port (Fix 2) instead of stopping it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Different error, &lt;code&gt;EACCES&lt;/code&gt;:&lt;/strong&gt; that's a permissions problem, not a busy port. Ports below 1024 often need admin rights; use a higher port.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Setting up a Windows dev machine? See &lt;a href="https://ondevkit.in/blog/github-ssh-key-windows" rel="noopener noreferrer"&gt;how to set up a GitHub SSH key on Windows&lt;/a&gt;. To understand when &lt;code&gt;listen()&lt;/code&gt; callbacks run, try these &lt;a href="https://ondevkit.in/blog/nodejs-event-loop-interview-questions" rel="noopener noreferrer"&gt;Node.js event loop interview questions&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://ondevkit.in/blog/fix-eaddrinuse-address-already-in-use" rel="noopener noreferrer"&gt;OnDevKit&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>windows</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
