0

I have a problem where I want to return a error (if there is one) and then print it.
I have a main.js file with:

const webserver = require('./webserver.js');
webserver.start();
//Here i want to print the error if there is one

and a module named webserver.js:

var webserver = {
    start: async function () {
        let serv = server.listen('a', () => { //<- "a" would give an error
            console.log(`Listening at http://localhost:${port}`)
        }).on('error', function (err) {
            return {'num': 403,'err': err}; //<- this doesn't work
        });
    }
}
module.exports = webserver;

How do I have to change my code so that I can return the error if there is one and receive it in my main.js file?

Luis Ka
  • 95
  • 7

1 Answers1

0

Solved it like this:

start: function () {
    return new Promise((respond, reject) => {
        serv = server.listen(config.port, () => {
            console.log(`Listening at http://localhost:${port}`)
        }).on('error', function (err) {
            respond({
                'num': 403,
                'err': err
            });
        });
    })
}
Luis Ka
  • 95
  • 7