0.0.3 • Published 1 year ago

@fjrodafo/free-port v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Install it!

npm i @fjrodafo/free-port

Run it!

// Import the module
const { findAvailablePort } = require('@fjrodafo/free-port');
// 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

Full repository on github/gitlab.

Visit the npm package website here.

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

2 years ago

2.0.0

2 years ago

1.0.0

2 years ago