Skip to content

Instantly share code, notes, and snippets.

@johnhunter
Last active July 26, 2023 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnhunter/bbc88d5d5424bc719f109fd71995a21c to your computer and use it in GitHub Desktop.
Save johnhunter/bbc88d5d5424bc719f109fd71995a21c to your computer and use it in GitHub Desktop.
Kill node processes bound to a specific port (MacOS)
#!/bin/bash
touch temp.text
lsof -n -i4TCP:$1 | awk '{print $2}' >temp.text
pidToStop=$( (sed '2q;d' temp.text))
>temp.text
if [[ -n $pidToStop ]]; then
kill -9 $pidToStop
echo "Killed process $pidToStop running on port $1."
else
echo "Sorry nothing running on port $1"
fi
rm temp.text
@johnhunter
Copy link
Author

johnhunter commented Jul 26, 2023

  • Save file to usr/local/bin/
  • Useage: killnode 3000

@johnhunter
Copy link
Author

Will probably have to sudo to create the file, and sudo chmod a+x killnode to make it executable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment