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! πŸš€

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay