how to properly close node-express server?

app.listen() returns http.Server. You should invoke close() on that instance and not on app instance.

Ex.

app.get(
    '/auth/github/callback',
    passport.authenticate('github', { failureRedirect: '/login' }),
    function(req, res) {
        res.redirect("https://stackoverflow.com/");

        setTimeout(function () {
            server.close();
            // ^^^^^^^^^^^
        }, 3000)
    }
);

var server = app.listen('http://localhost:5000/');
// ^^^^^^^^^^

You can inspect sources: /node_modules/express/lib/application.js

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)