DEV Community

TenE
TenE

Posted on

1

Kill Any Process by Port Instantly with kill-my-port πŸš€

Introduction

Have you ever run into the frustrating issue where a port is already in use, blocking you from starting your app? Manually finding and killing processes is time-consuming. That’s why I built kill-my-port, a simple CLI tool that helps you instantly free up any port with just one command!

Why kill-my-port?

When working with Node.js, React, Next.js, Express, Django, or any server-based app, you might encounter errors like:

Error: listen EADDRINUSE: address already in use :::3000
Enter fullscreen mode Exit fullscreen mode

Instead of manually searching for processes and killing them, kill-my-port does the job for you instantly.

πŸš€ Key Features:

βœ… Find & Kill processes by port automatically

βœ… Works on Windows, macOS, and Linux

βœ… Lists all active ports if no port is provided

βœ… Fast, simple, and efficient

Installation & Usage

πŸ”₯ Quick Start (No Installation Required)

If you don’t want to install anything, just run:

npx kill-my-port 3000
Enter fullscreen mode Exit fullscreen mode

This will instantly find and kill any process using port 3000.

πŸ› οΈ Global Installation

For frequent use, install it globally:

npm install -g kill-my-port
Enter fullscreen mode Exit fullscreen mode

Now, you can use it anytime:

kill-my-port 3000
Enter fullscreen mode Exit fullscreen mode

πŸ” List Active Ports

If you don’t know which port is causing the issue, simply run:

kill-my-port
Enter fullscreen mode Exit fullscreen mode

It will display all active ports, allowing you to choose which one to kill.

How It Works

Under the hood, kill-my-port runs platform-specific commands:

  • Windows: Uses netstat & taskkill to find and terminate processes.
  • macOS/Linux: Uses lsof & kill -9 to achieve the same.

Example Usage

Let’s say your React app won’t start because port 5173 is already in use. Just run:

kill-my-port 5173
Enter fullscreen mode Exit fullscreen mode

You’ll see:

❗ Kill process running on port 5173? (y/n): y
βœ… Port 5173 has been freed.
Enter fullscreen mode Exit fullscreen mode

Now, restart your app without issues! πŸŽ‰

Where to Get It

πŸ”— GitHub: https://github.com/TenEplaysOfficial/kill-my-port

πŸ“¦ npm: https://www.npmjs.com/package/kill-my-port

Give it a try and let me know what you think! πŸš€

Top comments (0)

πŸ‘‹ Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay