From 71097aeab726d827c4ab839e3fc3c86a8711f6a0 Mon Sep 17 00:00:00 2001 From: Mateusz Krawczuk Date: Thu, 26 Mar 2020 16:56:18 +0100 Subject: [PATCH] Move success message to `app`'s `listen` callback. express's `server.listen` has an asynchronous nature and it's API enables providing a callback that is fired upon success. Now the success messaage is logged only when the server has been set up and listening on provided socket address, otherwise the error stack trace is printed. --- nodejs-role/app/app.js | 3 +-- nodejs/provisioning/app/app.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/nodejs-role/app/app.js b/nodejs-role/app/app.js index 595a531..394aeff 100644 --- a/nodejs-role/app/app.js +++ b/nodejs-role/app/app.js @@ -11,5 +11,4 @@ app.get('/', function(req, res){ }); // Listen on port 80 (like a true web server). -app.listen(80); -console.log('Express server started successfully.'); +app.listen(80, () => console.log('Express server started successfully.')); diff --git a/nodejs/provisioning/app/app.js b/nodejs/provisioning/app/app.js index 595a531..394aeff 100644 --- a/nodejs/provisioning/app/app.js +++ b/nodejs/provisioning/app/app.js @@ -11,5 +11,4 @@ app.get('/', function(req, res){ }); // Listen on port 80 (like a true web server). -app.listen(80); -console.log('Express server started successfully.'); +app.listen(80, () => console.log('Express server started successfully.'));