port-claim
If a port is in use, port-claim stops the process using it.
Table of Contents
Install
With npm
:
npm install --save port-claim
With yarn
:
yarn add port-claim
With pnpm
:
pnpm add port-claim
Usage
API
claimPort(portNumber: number): Promise
- Takes a port number as input.
- Checks if the port is in use (with detect-port).
- If the port is already in use, kills the process using it (with kill-port).
- Returns a promise that resolves when the port is successfully claimed, or rejects with an error if the process fails.
CLI
You can use port-claim
as a global package.
Install the package globally:
$ npm install -g port-claim
# OR with yarn
$ yarn global add port-claim
# OR with pnpm
$ pnpm add -g port-claim
Then:
# Claim a port
$ port-claim 3000
You can also use npx to port-claim
without installing:
# Claim a port
$ npx port-claim 3000
Example
example usage in a package.json pre script
"scripts": {
"predev": "port-claim 3000",
"dev": "nuxt dev"
},
Contributing
Got an idea for a new feature? Found a bug? Contributions are welcome! Please open up an issue or make a pull request.