first commit

This commit is contained in:
2026-09-08 20:28:54 +08:00
commit 2ada8d3d5a
37380 changed files with 4886169 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
root = true
[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[{package.json,*.yml}]
indent_style = space
indent_size = 2
+1
View File
@@ -0,0 +1 @@
* text=auto
+3
View File
@@ -0,0 +1,3 @@
language: node_js
node_js:
- 'node'
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Tiaan du Plessis
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+117
View File
@@ -0,0 +1,117 @@
<h1 align="center">kill-port</h1>
<div align="center">
<strong>Kill the process running on given port</strong>
</div>
<br>
<div align="center">
<a href="https://npmjs.org/package/kill-port">
<img src="https://img.shields.io/npm/v/kill-port.svg?style=flat-square" alt="Package version" />
</a>
<a href="https://npmjs.org/package/kill-port">
<img src="https://img.shields.io/npm/dm/kill-port.svg?style=flat-square" alt="Downloads" />
</a>
<a href="https://github.com/feross/standard">
<img src="https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square" alt="Standard" />
</a>
<a href="https://travis-ci.org/tiaanduplessis/kill-port">
<img src="https://img.shields.io/travis/tiaanduplessis/kill-port.svg?style=flat-square" alt="Travis Build" />
</a>
<a href="https://badge.fury.io/gh/tiaanduplessis%2Fkill-port">
<img src="https://badge.fury.io/gh/tiaanduplessis%2Fkill-port.svg?style=flat-square" alt="GitHub version" />
</a>
<a href="https://dependencyci.com/github/tiaanduplessis/kill-port">
<img src="https://dependencyci.com/github/tiaanduplessis/kill-port/badge?style=flat-square" alt="Dependency CI" />
</a>
<a href="https://github.com/tiaanduplessis/kill-port/blob/master/LICENSE">
<img src="https://img.shields.io/npm/l/kill-port.svg?style=flat-square" alt="License" />
</a>
<a href="http://makeapullrequest.com">
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square" alt="PRs" />
</a>
</div>
<br>
<h2>Table of Contents</h2>
<details>
<summary>Table of Contents</summary>
<li><a href="#install">Install</a></li>
<li><a href="#usage">Usage</a></li>
<li><a href="#api">API</a></li>
<li><a href="#cli">CLI</a></li>
<li><a href="#contribute">Contribute</a></li>
<li><a href="#license">License</a></li>
</details>
## Install
```sh
$ npm install --save kill-port
# OR
$ yarn add kill-port
```
## Usage
```js
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)
})
```
## API
The module exports a single function that takes a port number as argument. It returns a promise.
## CLI
```sh
$ npm install --global kill-port
# OR
$ yarn global add kill-port
```
Then:
```sh
$ kill-port --port 8080
# OR
$ kill-port 9000
# OR you can use UDP
$ kill-port 9000 --method udp
```
You can also kill multiple ports:
```sh
$ kill-port --port 8080,5000,3000
# OR
$ kill-port 9000 3000 5000
```
## Contribute
Contributions are welcome. Please open up an issue or create PR if you would like to help out.
## License
Licensed under the MIT License.
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env node
'use strict'
const kill = require('./')
const args = require('get-them-args')(process.argv.slice(2))
const verbose = args.verbose || false
let port = args.port ? args.port.toString().split(',') : args.unknown
const method = args.method || 'tcp'
if (!Array.isArray(port)) {
port = [port]
}
Promise.all(port.map(current => {
return kill(current, method)
.then((result) => {
console.log(`Process on port ${current} killed`)
verbose && console.log(result)
})
.catch((error) => {
console.log(`Could not kill process on port ${port}`)
verbose && console.log(error)
})
}))
+19
View File
@@ -0,0 +1,19 @@
const kill = require('./')
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(() => {
kill(port)
.then(console.log)
.catch(console.log)
}, 1000)
})
+37
View File
@@ -0,0 +1,37 @@
'use strict'
const sh = require('shell-exec')
module.exports = function (port, method = 'tcp') {
port = Number.parseInt(port)
if (!port) {
return Promise.reject(new Error('Invalid argument provided for port'))
}
if (process.platform === 'win32') {
return sh('netstat -nao')
.then(res => {
const { stdout } = res
if (!stdout) return res
const lines = stdout.split('\n')
// The second white-space delimited column of netstat output is the local port,
// which is the only port we care about.
// The regex here will match only the local port column of the output
const lineWithLocalPortRegEx = new RegExp(`^ *${method.toUpperCase()} *[^ ]*:${port}`, 'gm')
const linesWithLocalPort = lines.filter(line => line.match(lineWithLocalPortRegEx))
const pids = linesWithLocalPort.reduce((acc, line) => {
const match = line.match(/(\d*)\w*(\n|$)/gm)
return match && match[0] && !acc.includes(match[0]) ? acc.concat(match[0]) : acc
}, [])
return sh(`TaskKill /F /PID ${pids.join(' /PID ')}`)
})
}
return sh(
`lsof -i ${method === 'udp' ? 'udp' : 'tcp'}:${port} | grep ${method === 'udp' ? 'UDP' : 'LISTEN'} | awk '{print $2}' | xargs kill -9`
)
}
+49
View File
@@ -0,0 +1,49 @@
{
"name": "kill-port",
"version": "1.6.1",
"description": "Kill the process running on given port",
"license": "MIT",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/tiaanduplessis/kill-port.git"
},
"homepage": "https://github.com/tiaanduplessis/kill-port",
"bugs": "https://github.com/tiaanduplessis/kill-port/issues",
"author": "Tiaan du Plessis",
"bin": {
"kill-port": "cli.js"
},
"scripts": {
"start": "npm run dev",
"pretest": "npm run lint",
"test": "jest --env=node",
"test:watch": "npm test -- --watch",
"coverage": "npm test -- --coverage",
"lint": "standard --fix",
"precommit": "npm test",
"check": "npm-check -u"
},
"keywords": [
"port",
"process",
"kill",
"kill-port",
"port"
],
"dependencies": {
"get-them-args": "1.3.2",
"shell-exec": "1.0.2"
},
"devDependencies": {
"husky": "4.2.5",
"jest": "26.1.0",
"npm-check": "^5.9.2",
"standard": "14.3.4"
},
"standard": {
"env": {
"jest": true
}
}
}
+5
View File
@@ -0,0 +1,5 @@
const kill = require('./')
test('kill-port', () => {
expect(kill).toBeDefined()
})