Get a unique port number based on a file path.
npm install path-to-portGenerate a consistent port number (3000-9999) from any file path. The same path always returns the same port.
``bash`
npm install -g path-to-port
`bash
npx path-to-port /user/hello5847
npx path-to-port /var/www/myapp
The 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
$3
`javascript
const { pathToPort } = require('path-to-port');const port = pathToPort('/user/hello');
console.log(port); // 5847
``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)
MIT