@fjrodafo/free-port

0.0.4 • Public • Published

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.

Package Sidebar

Install

npm i @fjrodafo/free-port

Weekly Downloads

0

Version

0.0.4

License

MIT

Unpacked Size

3.32 kB

Total Files

4

Last publish

Collaborators

  • fjrodafo