path-to-port
v0.1.0
Published
Get a unique port number based on a file path.
Readme
path-to-port
Generate a consistent port number (3000-9999) from any file path. The same path always returns the same port.
Installation
npm install -g path-to-portUsage
CLI
npx path-to-port /user/hello
# 5847
npx path-to-port /var/www/myapp
# 7234The same path will always return the same port, making it useful for:
- Assigning consistent dev server ports per project
- Avoiding port conflicts across different projects
- Reproducible development environments
Programmatic
const { pathToPort } = require('path-to-port');
const port = pathToPort('/user/hello');
console.log(port); // 5847How It Works
The path is hashed using a simple string hash algorithm, then mapped to the port range 3000-9999. This gives 7000 possible ports while avoiding:
- Privileged ports (< 1024)
- Commonly used ports (1024-2999)
License
MIT
