2.0.1 • Published 8 months ago

@fjrodafo/port-finder v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Install it!

npm i @fjrodafo/port-finder

Run it!

// Import the module
const { findAvailablePort } = require('@fjrodafo/port-finder');
// It will find an available port in case port 3000 is busy
findAvailablePort(3000).then(port => {
    server.listen(port, () => {
        console.log(`Server listening on port http://localhost:${port}`);
    });
});

Environment variable

// You can create an environment variable for advanced use
const desiredPort = process.env.PORT ?? 3000;

findAvailablePort(desiredPort).then(port => {
    server.listen(port, () => {
        console.log(`Server listening on port http://localhost:${port}`);
    });
});

Links

Contribute to the repository on GitHub.

Check out this package on GitHub Packages or npmjs website!

2.0.1

8 months ago

2.0.0

9 months ago

1.0.0

9 months ago