Skip to content

jasenmichael/port-claim

Repository files navigation

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

import portClaim from "port-claim"
// or 
const portClaim = require("port-claim")

portClaim(3000)
// or
portClaim(3000, "-v")

API

portClaim(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 no port was passed, or 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

CLI Usage

npx port-claim 3000 -h

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.

License

MIT © @jasenmichael

About

If a port is in use, port-claim stops the process using it.

Resources

License

Stars

Watchers

Forks

Packages

No packages published