Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
The kill-port npm package is a utility that allows you to kill processes running on specific ports. This can be particularly useful for developers who need to free up ports that are being used by other applications or processes.
Kill a specific port
This feature allows you to kill a process running on a specific port. In this example, the process running on port 3000 is terminated.
const kill = require('kill-port');
kill(3000)
.then(() => {
console.log('Port 3000 killed');
})
.catch((err) => {
console.error('Error killing port 3000:', err);
});
Kill a port with a specific protocol
This feature allows you to specify the protocol (TCP or UDP) when killing a port. In this example, the TCP process running on port 3000 is terminated.
const kill = require('kill-port');
kill(3000, 'tcp')
.then(() => {
console.log('TCP process on port 3000 killed');
})
.catch((err) => {
console.error('Error killing TCP process on port 3000:', err);
});
Kill multiple ports
This feature allows you to kill multiple ports simultaneously. In this example, the processes running on ports 3000 and 4000 are terminated.
const kill = require('kill-port');
Promise.all([kill(3000), kill(4000)])
.then(() => {
console.log('Ports 3000 and 4000 killed');
})
.catch((err) => {
console.error('Error killing ports:', err);
});
fkill is a package that allows you to kill processes by port, name, or PID. It provides a more versatile approach compared to kill-port, which is focused solely on killing ports.
kill-process-by-port is another package that specifically targets processes running on a given port. It is similar to kill-port but may have different implementation details and options.
port-killer is a utility for killing processes running on specific ports. It offers similar functionality to kill-port but may have different command-line options and usage patterns.
With npm
:
npm install --save kill-port
With yarn
:
yarn add kill-port
With pnpm
:
pnpm add kill-port
const kill = require('kill-port')
const http = require('http')
const port = 8080
const server = http.createServer((req, res) => {
res.writeHead(200, {
'Content-Type': 'text/plain'
})
res.end('Hi!')
})
server.listen(port, () => {
setTimeout(() => {
// Currently you can kill ports running on TCP or UDP protocols
kill(port, 'tcp')
.then(console.log)
.catch(console.log)
}, 1000)
})
The module exports a single function that takes a port number as argument. It returns a promise.
You can use kill-port
as a global package.
Install the package globally:
$ npm install --global kill-port
# OR
$ yarn global add kill-port
Then:
$ kill-port --port 8080
# OR
$ kill-port 9000
# OR you can use UDP
$ kill-port 9000 --method udp
You can also kill multiple ports:
$ kill-port --port 8080,5000,3000
# OR
$ kill-port 9000 3000 5000
You can also use npx to kill-port
without installing:
# Kill a single port
$ npx kill-port --port 8080
$ npx kill-port 8080
# Use UDP
$ npx kill-port 9000 --method udp
# Kill multiple ports
$ npx kill-port --port 8080,5000,3000
$ npx kill-port 9000 3000 5000
Got an idea for a new feature? Found a bug? Contributions are welcome! Please open up an issue or make a pull request.
FAQs
Kill process running on given port
The npm package kill-port receives a total of 197,288 weekly downloads. As such, kill-port popularity was classified as popular.
We found that kill-port demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.