Quick way to fix the Port is Already in Use Error

Quick way to fix the Port is Already in Use Error

ยท

2 min read

Have you ever struggled with the the port is already in use error while starting the application?

A lot of times when we are using multiple applications or forget to stop the previous process, we get the the port is already in use error.

Then we try to find the process using that port and then kill it or maybe restart the machine.

There is an easier way to do it. Just execute the following command in the terminal:

npx kill-port port_number

and the process using that port will be killed.

For example,

npx kill-port 3000

will kill the process using port 3000.

To kill multiple ports pass the ports separated by space

npx kill-port 3000 5000 7000

kill-port in an npm package which helps in killing any specified port or multiple ports at once.

If you want, you can install the kill-port npm package on your machine by running the following command:

npm install -g kill-port

Mac/Linux users may need to add sudo in front of it like this: sudo npm install -g kill-port.

Once installed, you can just execute the kill-port 3000 to kill the process using port 3000.

Thanks for reading

Starting with ES6, there are many useful additions to JavaScript like

  • ES6 Destructuring
  • Import and Export Syntax
  • Arrow functions
  • Promises
  • Async/await
  • Optional chaining operator and a lot more.

You can learn everything about all the ES6+ features in detail in my Mastering Modern JavaScript book.

Check out free preview contents of the book here.

Also, you can check out my free Introduction to React Router course to learn React Router from scratch.

Want to stay up to date with regular content regarding JavaScript, React, Node.js? Follow me on LinkedIn.

Did you find this article valuable?

Support Yogesh Chavan by becoming a sponsor. Any amount is appreciated!