kill my previous file on local host - node.js

I connected my file "smap" to localhost:3000 couple month ago when I was learning the npm.
Right now, I cannot remove it from localhost:3000
It keeps showing me old file:
smap#1.0.0 start /Users/Han
cross-env NODE_ENV=development ./node_modules/.bin/hjs-dev-server
Listening at http://localhost:3000
webpack built 2f3c2c9a3eec810b8e79 in 2453ms
Does anyone know how can I remove it from my local host? I tried
Find: lsof -i :3000
Kill: kill -9 <PID>
but it did not work.
Since I get a new file, want to connect it with localhost.

Can you try the following commands?
Find: sudo lsof -i tcp:3000
Kill: sudo kill -9 PID

Related

How to kill the port node env is using

I am collaborating on a deploy using sudo with ssh access to aws ec2 instance.
The application starts up and throws the error
Error: listen EADDRINUSE :::4000
if I do:
sudo fuser 4000/tcp
I get:
4000/tcp: 1669
If I do:
sudo fuser -i -k 4000/tcp
I get:
4000/tcp: 1669 Kill process 1669 ? (y/N)
If I do:
y
It doesn't kill the port. I have stopped the app as well of course.
I don't have netstat.
Is this a privilege thing with the root access? I would try to change the port number but don't have that access right now.
Is there anything else I can try?
thanks
You can do this using a combination of kill and lsof.
sudo kill -9 $(sudo lsof -t -i:4000)
Which tells the os to terminate the process using port 4000.
sudo You're likely going to need root level access
kill -9 tells the os to terminate the process
$(some command) command substitution
/ run the command
lsof -t implies terse output excluding
headers
lsof -i:PORT_NUMBER is used to filter the list by internet
address/port

listen EADDRINUSE: address already in use :::5000

In my application, I use concurrently to run both backend and front end simultaneously. After ctrl + c, strill the port 5000 is running. Also, port 3000 is running. I have to manually kill processes. How can I solve this?
Run cmd.exe as 'Administrator':
C:\Windows\System32>taskkill /F /IM node.exe
run pa -xa | grep node
you will get result with processid
4476 pts/0 Sl+ 0:01 node index.js
then kill the process with kill -9 4476
as simple as that
lsof -ti finds open files(sockets are files in nix based systems) -t removes the headers, so that we can pipe into kill(We just want the process id), -i lets lsof find the file based off the internet address. We do not have to provide the full address, we can just search by port, by using the pattern :port.
Some commands accept input from stdin, and we can pipe directly to them, kill is not one of those commands, so we must use xargs(It reads from stdin, and calls the specified command with the input from stdin).
Finally the ; lets us execute both commands irrespective of one another. Regardless of whether lsof -ti:3000 | xargs kill succeeds or fails,
lsof -ti:5000 | xargs kill will run, and vice versa.
lsof -ti:3000 | xargs kill; lsof -ti:5000 | xargs kill
Restart your laptop/server, it will release all the busy ports, then try again... you can also use
ps aux | grep node
and then kill the process using:
kill -9 PID..
You can kill all the processes that are using node it can also kill a system process
Not preferred: killall -9 node
but most of the times it wont work for nodemon, and didnt work for me.
You can fix this issue by killing the address in use or may simply restart your device.
1- For Linux to Kill the address in use, use the following command
sudo kill $(sudo lsof -t -i:8080)
where replace 8080 with your app address.
you can simply restart your laptop or change the port number it should work

Stop node.js program from command line

I have a simple TCP server that listens on a port.
var net = require("net");
var server = net.createServer(function(socket) {
socket.end("Hello!\n");
});
server.listen(7777);
I start it with node server.js and then close it with Ctrl + Z on Mac. When I try to run it again with node server.js I get this error message:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: listen EADDRINUSE
at errnoException (net.js:670:11)
at Array.0 (net.js:771:26)
at EventEmitter._tickCallback (node.js:192:41)
Am I closing the program the wrong way? How can I prevent this from happening?
To end the program, you should be using Ctrl + C. If you do that, it sends SIGINT, which allows the program to end gracefully, unbinding from any ports it is listening on.
See also: https://superuser.com/a/262948/48624
Ctrl+Z suspends it, which means it can still be running.
Ctrl+C will actually kill it.
you can also kill it manually like this:
ps aux | grep node
Find the process ID (second from the left):
kill -9 PROCESS_ID
This may also work
killall node
Or alternatively you can do all of these in one line:
kill -9 $(ps aux | grep '\snode\s' | awk '{print $2}')
You can replace node inside '\snode\s' with any other process name.
Resume and kill the process:
Ctrl+Z suspends it, which means it is still running as a suspended background process.
You are likely now at a terminal prompt...
Give the command fg to resume the process in the foreground.
type Ctrl+C to properly kill it.
Alternatively, you can kill it manually like this:
(NOTE: the following commands may require root, so sudo ... is your friend)
pkill -9 node
or, if you don't have pkill, this may work:
killall node
or perhaps this:
kill $(ps -e | grep node | awk '{print $1}')
sometimes the process will list its own grep, in which case you'll need:
kill $(ps -e | grep dmn | awk '{print $2}')
.
h/t #ruffin from the comments on the question itself. I had the same issue and his comment helped me solve it myself.
If you are running Node.js interactively (the REPL):
Ctrl + C will take back you to > prompt then type:
process.exit()
or just use Ctrl + D.
you can type .exit to quit node js REPL
$ sudo killall node in another terminal works on mac, while killall node not working:
$ killall node
No matching processes belonging to you were found
on linux try: pkill node
on windows:
Taskkill /IM node.exe /F
or
from subprocess import call
call(['taskkill', '/IM', 'node.exe', '/F'])
you can work following command to be specific in localserver kill(here: 8000)
http://localhost:8000/ kill PID(processId):
$:lsof -i tcp:8000
It will give you following groups of TCPs:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 21521 ubuntu 12u IPv6 345668 0t0 TCP *:8000 (LISTEN)
$:kill -9 21521
It will kill processId corresponding to TCP*:8000
You can use fuser to get what you want to be done.
In order to obtain the process ids of the tasks running on a port you can do:
fuser <<target_port>>/tcp
Let's say the port is 8888, the command becomes:
fuser 8888/tcp
And to kill a process that is running on a port, simply add -k switch.
fuser <<target_port>>/tcp -k
Example (port is 8888):
fuser 8888/tcp -k
That's it! It will close the process listening on the port.
I usually do this before running my server application.
For MacOS
Open terminal
Run the below code and hit enter
sudo kill $(sudo lsof -t -i:4200)
Though this is a late answer, I found this from NodeJS docs:
The 'exit' event is emitted when the REPL is exited either by receiving the .exit command as input, the user pressing <ctrl>-C twice to signal SIGINT, or by pressing <ctrl>-D to signal 'end' on the input stream. The listener callback is invoked without any arguments.
So to summarize you can exit by:
Typing .exit in nodejs REPL.
Pressing <ctrl>-C twice.
pressing <ctrl>-D.
process.exit(0) meaning a natural exit from REPL. If you want to return any other status you can return a non zero number.
process.kill(process.pid) is the way to kill using nodejs api from within your code or from REPL.
If you want to stop your server with npm stop or something like this. You can write the code that kill your server process as:
require('child_process').exec(`kill -9 ${pid}`)
Check this link for the detail:
https://gist.github.com/dominhhai/aa7f3314ad27e2c50fd5
I'm adding this answer because for many projects with production deployments, we have scripts that stop these processes so we don't have to.
A clean way to manage your Node Server processes is using the forever package (from NPM).
Example:
Install Forever
npm install forever -g
Run Node Server
forever start -al ./logs/forever.log -ao ./logs/out.log -ae ./logs/err.log server.js
Result:
info: Forever processing file: server.js
Shutdown Node Server
forever stop server.js
Result
info: Forever stopped process:
uid command script forever pid id logfile uptime
[0] sBSj "/usr/bin/nodejs/node" ~/path/to/your/project/server.js 23084 13176 ~/.forever/forever.log 0:0:0:0.247
This will cleanly shutdown your Server application.
I ran into an issue where I have multiple node servers running, and I want to just kill one of them and redeploy it from a script.
Note: This example is in a bash shell on Mac.
To do so I make sure to make my node call as specific as possible. For example rather than calling node server.js from the apps directory, I call node app_name_1/app/server.js
Then I can kill it using:
kill -9 $(ps aux | grep 'node\ app_name_1/app/server.js' | awk '{print $2}')
This will only kill the node process running app_name_1/app/server.js.
If you ran node app_name_2/app/server.js this node process will continue to run.
If you decide you want to kill them all you can use killall node as others have mentioned.
Late answer but on windows, opening up the task manager with CTRL+ALT+DEL then killing Node.js processes will solve this error.
My use case: on MacOS, run/rerun multiple node servers on different ports from a script
run: "cd $PATH1 && node server1.js & cd $PATH2 && node server2.js & ..."
stop1: "kill -9 $(lsof -nP -i4TCP:$PORT1 | grep LISTEN | awk '{print $2}')"
stop2, stop3...
rerun: "stop1 & stop2 & ... & stopN ; run
for more info about finding a process by a port: Who is listening on a given TCP port on Mac OS X?
For windows first search the PID with your port number
netstat -ano | findStr "portNumber"
After that, kill the task, make sure you are in root of your "c" drive
And the command will be taskkill /F /PID your pid
if you are using VS Code and terminal select node from the right side dropdown first and then do Ctrl + C. Then It will work
Press y when you are prompted.
Thanks

how to release localhost from Error: listen EADDRINUSE

i am testing a server written in nodejs on windows 7
and when i try to run the tester in the command line i get the following error
Error: listen EADDRINUSE
at errnoException (net.js:614:11)
at Array.0 (net.js:704:26)
at EventEmitter._tickCallback (node.js:192:40)
how can I fix it without rebooting?
Run:
ps -ax | grep node
You'll get something like:
60778 ?? 0:00.62 /usr/local/bin/node abc.js
Then do:
kill -9 60778
It means the address you are trying to bind the server to is in use. Try another port or close the program using that port.
On Linux (Ubuntu derivatives at least)
killall node
is easier than this form.
ps | grep <something>
kill <somepid>
Neither will work if you have a orphaned child holding the port. Instead, do this:
netstat -punta | grep <port>
If the port is being held you'll see something like this:
tcp 0 0.0.0.0:<port> 0.0.0.* LISTEN <pid>/<parent>
Now kill by pid:
kill -9 <pid>
The following command will give you a list of node processes running.
ps | grep node
To free up that port, stop the process using the following.
kill <processId>
You are getting the error EADDRINUSE because the port, which your application wants to use, is occupied by another process. To release this port, you need to terminate the occupying process.
Since you are on Windows, you can terminate the process using the command prompt (cmd). With the cmd you can discover the process ID (PID) of the blocking application. You will need the PID in order to terminate / kill the process.
Here is a step-by-step guide...
Find all processes which are running on a specified port (in this example, Port is "3000"):
netstat -ano | find ":3000 "
The netstat command will list up all processes running on the specified port. In the last column of the netstat results you can see the PIDs (in this example, PID is "8308"). You can find out more about a specific PID by running the following command:
tasklist /fi "pid eq 8308"
If you want to terminate a process, you can do that with the following command by using its PID (in this example, PID is "8308"):
taskkill /pid 8308 /f
Screenshot
When you get an error Error: listen EADDRINUSE,
Try running the following shell commands:
netstat -a -o | grep 8080
taskkill /F /PID 6204
I greped for 8080, because I know my server is running on port 8080. (static tells me when I start it: 'serving "." at http://127.0.0.1:8080'.) You might have to search for a different port.
suppose your server is running on port 3000
lsof -i tcp:3000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 11716 arun 11u IPv6 159175 0t0 TCP *:3000 (LISTEN)
after that use kill -9 <pid>
in the above case sudo kill -9 11716
use below command to kill a process running at a certain port - 3000 in this example below
kill -9 $(lsof -t -i:3000)
One possible solution that worked for me was simply to close the window in browser where I had the corresponding "http://localhost:3000/" script running.
When you get an error
Error: listen EADDRINUSE
Open command prompt and type the following instructions:
netstat -a -o | grep 8080
taskkill /F /PID** <*ur Process ID no*>
after that restart phone gap interface.
If you want to know which process ID phonegap is using, open TASK MANAGER and look at the Column heading PID and find the PID no.
Check the Process ID
sudo lsof -i:8081
Than kill the particular Process
sudo kill -9 2925
The aforementioned killall -9 node, suggested by Patrick works as expected and solves the problem but you may want to read the edit part of this very answer about why kill -9 may not be the best way to do it.
On top of that you might want to target a single process rather than blindly killing all active processes.
In that case, first get the process ID (PID) of the process running on that port (say 8888):
lsof -i tcp:8888
This will return something like:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 57385 You 11u IPv6 0xac745b2749fd2be3 0t0 TCP *:ddi-tcp-1
(LISTEN)
Then just do (ps - actually do not. Please keep reading below):
kill -9 57385
This works on Mac:
Step 1.
sudo lsof -i tcp:3000 (or whatever port you want to kill)
Above command will give you the Process Id(s) currently holding the port.
Step 2.
Kill -9 <pid>
you can change your port in app.js or in ur project configuration file.
default('port', 80)
and to see if port 80 is already in use you can do
netstat -antp |grep 80
netstat -antp |grep node
you might wanna see if node process is already running or not.
ps -ef |grep node
and if you find its already running, you can kill it using
killall node
I created 2 servers, listening on same port 8081, running from same code, while learning
1st server creation shud have worked
2nd server creation failed with EADDRINUSE
node.js callback delays might be reason behind neither worked, or 2nd server creation had exception, and program exited, so 1st server is also closed
2 server issue hint, I got from:
How to fix Error: listen EADDRINUSE while using nodejs?
Error: listen EADDRINUSE to solve it in Ubuntu run in terminal netstat -nptl and after this kill -9 {process-number} this command is to kill node process and now you can try to run again node server.js command
Ex
listen EADDRINUSE :::8080
netstat -nptl
tcp6 0 0 :::9000 :::* LISTEN 9660/java
tcp6 0 0 :::5800 :::* LISTEN -
tcp6 0 0 :::5900 :::* LISTEN -
tcp6 0 0 :::8080 :::* LISTEN 10401/node
tcp6 0 0 :::20080 :::* LISTEN 9660/java
tcp6 0 0 :::80 :::* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
tcp6 0 0 :::10137 :::* LISTEN 9660/java
kill -9 10401
I have node red installed on my Mac and my Raspberry Pi. Had the exact same problem and doing 'killall' didn't help. Once I shut down the Raspberry Pi and restarted my computer it worked fine.
It may be possible that you have tried to run the npm start command in two different tabs .you cant run npm start when it is already running in some tab.check it once .
To anyone who has tried all of the above, but still can't find the rouge process, try them all again but make sure you include "sudo" in front of the commands.
If you like UI more, find the process Node.js in windows task manager and kill it.
ps -ef |grep node
find app.js ,
kill pid of app.js
simply kill the node
as
pkill -9 node
in terminal of ubantu
than start node
You will need to kill the port by trying to use the following command on the terminal
$ sudo killall -9 nodejs
I have solved this issue by adding below in my package.json for killing active PORT - 4000 (in my case) Running on WSL2/Linux/Mac
"scripts": {
"dev": "nodemon app.js",
"predev":"fuser -k 4000/tcp && echo 'Terminated' || echo 'Nothing was running on the PORT'",
}
Source
I Just delete that (cmd) Terminal and open another terminal and run again
node myfile.js
it works awesomely for me.
It's might be too late but it's working like a charm.
You need pm2 to be installed
npm install -g pm2
To stoping the current running server (server.js):
pm2 stop -f server.js
It's year 2022 now and I am on Monterey (Mac user).
lsof -i tcp:3000
Kill -9 <PID shown in your list>
To kill node server first run this command in your terminal :
top
open another window then copy the server id from the previous window: PID number -9 kill
so now you killed your node server try again to run your app.
I used the command netstat -ano | grep "portnumber" in order to list out the port number/PID for that process.
Then, you can use taskkill -f //pid 111111 to kill the process, last value being the pid you find from the first command.
One problem I run into at times is node respawning even after killing the process, so I have to use the good old task manager to manually kill the node process.
In window, please execute this command:
taskkill /F /PID 1952

Find (and kill) process locking port 3000 on Mac [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed last year.
The community reviewed whether to reopen this question 8 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
How do I find (and kill) processes that listen to/use my TCP ports? I'm on macOS.
Sometimes, after a crash or some bug, my Rails app is locking port 3000. I can't find it using ps -ef...
When running
rails server
I get
Address already in use - bind(2) (Errno::EADDRINUSE)
The same issue happens when stopping Node.js process. Even after the process is stopped and the app stops running, port 3000 is locked. When starting the app again, getting
Address already in use (Errno::EADDRINUSE)
You can try netstat
netstat -vanp tcp | grep 3000
For macOS El Capitan and newer (or if your netstat doesn't support -p), use lsof
lsof -i tcp:3000
Find:
sudo lsof -i :3000
Kill:
kill -9 <PID>
PLEASE NOTE: -9 kills the process immediately, and gives it no chance of cleaning up after itself. This may cause problems. Consider using -15 (TERM) or -3 (QUIT) for a softer termination which allows the process to clean up after itself.
Quick and easiest solution:
kill -9 $(lsof -ti:3000)
For multiple ports:
kill -9 $(lsof -ti:3000,3001)
#3000 is the port to be freed
Kill multiple ports with single line command:
kill -9 $(lsof -ti:3000,3001)
#Here multiple ports 3000 and 3001 are the ports to be freed
lsof -ti:3000
If the port is occupied, the above command will return something like this: 82500 (Process ID)
lsof -ti:3001
82499
lsof -ti:3001,3000
82499
82500
kill -9 $(lsof -ti:3001,3000)
Terminates both 82499 and 82500 processes in a single command.
For using this in package.json scripts:
"scripts": {
"start": "kill -9 $(lsof -ti:3000,3001) && npm start"
}
In terminal you can use:
npm run start
Nothing above worked for me. Anyone else with my experience could try the following (worked for me):
Run:
lsof -i :3000 (where 3000 is your current port in use)
then check status of the reported PID :
ps ax | grep <PID>
finally, "begone with it":
kill -QUIT <PID>
A one-liner to extract the PID of the process using port 3000 and kill it.
lsof -ti:3000 | xargs kill
The -t flag removes everything but the PID from the lsof output, making it easy to kill it.
This single command line is easy to remember:
npx kill-port 3000
You can also kill multiple ports at once:
npx kill-port 3000 3001 3002
For a more powerful tool with search:
npx fkill-cli
PS: They use third party javascript packages. npx comes built in with Node.js.
Sources: tweet | github
You can use lsof -i:3000.
That is "List Open Files". This gives you a list of the processes and which files and ports they use.
To forcefully kill a process like that, use the following command
lsof -n -i4TCP:3000
OR lsof -i:3000
Where 3000 is the port number the process is running at
this returns the process id(PID)
and run
kill -9 "PID"
Replace PID with the number you get after running the first command
Why kill -9 PID does not work?
If you trying to kill a process with its PID and it still runs on another PID, it looks like you have started that process in a different account most probably root account. so Login in with sudo su and kill it
In your .bash_profile, create a shortcut for terminate the 3000 process:
terminate(){
lsof -P | grep ':3000' | awk '{print $2}' | xargs kill -9
}
Then, call $terminate if it's blocked.
To kill multi ports.
$ npx kill-port 3000 8080 8081
Process on port 3000 killed
Process on port 8080 killed
Process on port 8081 killed
Hope this help!
lsof -P | grep ':3000' | awk '{print $2}'
This will give you just the pid, tested on MacOS.
Execute in command line on OS-X El Captain:
kill -kill `lsof -t -i tcp:3000`
Terse option of lsof returns just the PID.
One of the ways to kill a process on a port is to use the python library: freeport (https://pypi.python.org/pypi/freeport/0.1.9) . Once installed, simply:
# install freeport
pip install freeport
# Once freeport is installed, use it as follows
$ freeport 3000
Port 3000 is free. Process 16130 killed successfully
To view the processes blocking the port:
netstat -vanp tcp | grep 3000
To Kill the processes blocking the port:
kill $(lsof -t -i :3000)
Find and kill:
This single command line is easy and works correctly.
kill -9 $(lsof -ti tcp:3000)
Find the open connection
lsof -i -P | grep -i "listen"
Kill by process ID
kill -9 'PID'
Possible ways to achieve this:
top
The top command is the traditional way to view your system’s resource usage and see the processes that are taking up the most system resources. Top displays a list of processes, with the ones using the most CPU at the top.
ps
The ps command lists running processes. The following command lists all processes running on your system:
ps -A
You could also pipe the output through grep to search for a specific process without using any other commands. The following command would search for the Firefox process:
ps -A | grep firefox
The most common way of passing signals to a program is with the kill command.
kill PID_of_target_process
lsof
List of all open files and the processes that opened them.
lsof -i -P | grep -i "listen"
kill -9 PID
or
lsof -i tcp:3000
lsof -i tcp:port_number - will list the process running on that port
kill -9 PID - will kill the process
in your case, it will be
lsof -i tcp:3000 from your terminal
find the PID of process
kill -9 PID
I made a little function for this, add it to your rc file (.bashrc, .zshrc or whatever)
function kill-by-port {
if [ "$1" != "" ]
then
kill -9 $(lsof -ni tcp:"$1" | awk 'FNR==2{print $2}')
else
echo "Missing argument! Usage: kill-by-port $PORT"
fi
}
then you can just type kill-by-port 3000 to kill your rails server (substituting 3000 for whatever port it's running on)
failing that, you could always just type kill -9 $(cat tmp/pids/server.pid) from the rails root directory
These two commands will help you find and kill server process
lsof -wni tcp:3000
kill -9 pid
kill -9 $(lsof -ti:3000)
works for me on macOS always.
If you're working on a node.js project, you can add it to package.json scripts like;
"scripts": {
...
"killme": "kill -9 $(lsof -ti:3000)",
...
},
then
npm run killme
--
Also if you want to add system wide alias for your macOS, follow these steps;
Navigate to your home directory:
cd ~
Open up .bash_profile or zsh profile using nano or vim:
vi .bash_profile
Add an alias (press i):
alias killme="kill -9 $(lsof -ti:3000)"
save file
restart terminal
type killme to the terminal
Of course you can change port 3000 to what you want.
Add to ~/.bash_profile:
function killTcpListen () {
kill -QUIT $(sudo lsof -sTCP:LISTEN -i tcp:$1 -t)
}
Then source ~/.bash_profile and run
killTcpListen 8080
Using sindresorhus's fkill tool, you can do this:
$ fkill :3000
Works for me for terminating node (Mac OS Catalina)
killall -9 node
TL;DR:
lsof -ti tcp:3000 -sTCP:LISTEN | xargs kill
If you're in a situation where there are both clients and servers using the port, e.g.:
$ lsof -i tcp:3000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 2043 benjiegillam 21u IPv4 0xb1b4330c68e5ad61 0t0 TCP localhost:3000->localhost:52557 (ESTABLISHED)
node 2043 benjiegillam 22u IPv4 0xb1b4330c8d393021 0t0 TCP localhost:3000->localhost:52344 (ESTABLISHED)
node 2043 benjiegillam 25u IPv4 0xb1b4330c8eaf16c1 0t0 TCP localhost:3000 (LISTEN)
Google 99004 benjiegillam 125u IPv4 0xb1b4330c8bb05021 0t0 TCP localhost:52557->localhost:3000 (ESTABLISHED)
Google 99004 benjiegillam 216u IPv4 0xb1b4330c8e5ea6c1 0t0 TCP localhost:52344->localhost:3000 (ESTABLISHED)
then you probably don't want to kill both.
In this situation you can use -sTCP:LISTEN to only show the pid of processes that are listening. Combining this with the -t terse format you can automatically kill the process:
lsof -ti tcp:3000 -sTCP:LISTEN | xargs kill
Here's a helper bash function to kill multiple processes by name or port
fkill() {
for i in $#;do export q=$i;if [[ $i == :* ]];then lsof -i$i|sed -n '1!p';
else ps aux|grep -i $i|grep -v grep;fi|awk '{print $2}'|\
xargs -I# sh -c 'kill -9 #&&printf "X %s->%s\n" $q #';done
}
Usage:
$ fkill [process name] [process port]
Example:
$ fkill someapp :8080 node :3333 :9000
You can try this
netstat -vanp tcp | grep 3000
I use:
lsof -wni tcp:3000
Get the PID, and:
kill -9 <PID>
my fav one-liner:
sudo kill `sudo lsof -t -i:3000`
To kill port 3000 on mac, run the below command
kill -9 $(lsof -t -i:3000 -sTCP:LISTEN)

Resources