Skip to content

EADDRINUSE code in express #4808

@tarunsinghh

Description

@tarunsinghh
// using nodejs we can write code to retry to listen on port using
const server = http.createServer().listen(3000);
server.on('error',function(err) {
    if (err.code === 'EADDRINUSE') {
        console.log('Address in use, retrying...');
        setTimeout(() => {
            server.close();
            server.listen(3000, 'localhost');
        }, 1000);
    }
});

how to do this same thing in express

const app = require('express')();
app.on('err',function(err) {
console.log('error occured'); // this doesnt work
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions