<?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: Anton Rosh</title>
    <description>The latest articles on DEV Community by Anton Rosh (@antonrosh).</description>
    <link>https://dev.to/antonrosh</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F750675%2F03193cc8-ad90-4c31-b38c-70b302b8dc45.jpg</url>
      <title>DEV Community: Anton Rosh</title>
      <link>https://dev.to/antonrosh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/antonrosh"/>
    <language>en</language>
    <item>
      <title>"Address Already in Use": A Simple Guide to Freeing Up Ports</title>
      <dc:creator>Anton Rosh</dc:creator>
      <pubDate>Sat, 27 May 2023 02:21:49 +0000</pubDate>
      <link>https://dev.to/antonrosh/address-already-in-use-a-simple-guide-to-freeing-up-ports-54g5</link>
      <guid>https://dev.to/antonrosh/address-already-in-use-a-simple-guide-to-freeing-up-ports-54g5</guid>
      <description>&lt;p&gt;As a developer, there's nothing quite as frustrating as being ready to launch your application, only to be greeted with an error like &lt;code&gt;EADDRINUSE&lt;/code&gt;. This common error message indicates that the port you're trying to use is already occupied by another process. In this post, we'll go through the steps you can take to identify and kill the process that's tying up your port, whether you're on a Mac, Linux, or Windows system.&lt;/p&gt;

&lt;h2&gt;
  
  
  What does EADDRINUSE mean?
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;EADDRINUSE&lt;/code&gt; error typically occurs when you're trying to start a server on a specific port, but that port is already being used by another process. This error is common across various languages and frameworks, including Node.js, Express.js, and in this case, Playwright with TypeScript.&lt;/p&gt;

&lt;p&gt;Here's an example of the &lt;code&gt;EADDRINUSE&lt;/code&gt; error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Error: listen EADDRINUSE: address already in use 127.0.0.1:9323
    at Server.setupListenHandle [as _listen2] (node:net:1372:16)
    at listenInCluster (node:net:1420:12)
    at GetAddrInfoReqWrap.doListen (node:net:1559:7)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:73:8) {
  code: 'EADDRINUSE',
  errno: -4091,
  syscall: 'listen',
  address: '127.0.0.1',
  port: 9323
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Identifying the Process
&lt;/h2&gt;

&lt;p&gt;To free up the port, we first need to identify the process that's using it. Here's how you can do this on different operating systems:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mac/Linux:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open your terminal and type in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo lsof -i :9323
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will give you a list of processes using port 9323, along with their PID (Process ID).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Windows:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open the command prompt and type in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;netstat -ano | findstr :9323
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PS C:\Users\YourUser\YourProject&amp;gt; netstat -ano|findstr "PID :9323"           
  Proto  Local Address          Foreign Address        State           PID
  TCP    127.0.0.1:9323         0.0.0.0:0              LISTENING       27924
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will provide a list of processes using port 9323, along with their PID.&lt;/p&gt;

&lt;h2&gt;
  
  
  Killing the Process
&lt;/h2&gt;

&lt;p&gt;Once you have the PID, you can kill the process:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mac/Linux:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Suppose the PID you found was 27924, you'd type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kill -9 27924
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Windows:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Again, if the PID was 27924, you'd type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;taskkill /PID 27924 /F
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Prevention is Better than Cure
&lt;/h2&gt;

&lt;p&gt;While it's good to know how to solve the &lt;code&gt;EADDRINUSE&lt;/code&gt; error, it's even better to prevent it from happening in the first place. Be mindful of the ports your applications are using and ensure they're appropriately closed when you're done.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;EADDRINUSE&lt;/code&gt; error can be a speed bump on your coding journey, but it's not an insurmountable one. With a little bit of terminal knowledge, you can quickly identify and eliminate the rogue process. So the next time this error pops up, you'll know exactly what&lt;/p&gt;

</description>
      <category>errors</category>
      <category>terminal</category>
      <category>ports</category>
      <category>process</category>
    </item>
  </channel>
</rss>
