Skip to content

Commit

Permalink
fix: listening on port undefined (freeCodeCamp#19)
Browse files Browse the repository at this point in the history
If PORT is not defined in .env, console.log("Listening on port "
+ process.env.PORT) will display "Listening on port undefined".
  • Loading branch information
Willyanto39 authored Jun 27, 2021
1 parent 0b39f20 commit 85bfa7b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ app.use(function(req, res, next) {
.send('Not Found');
});

const port = process.env.PORT || 3000;

//Start our server and tests!
app.listen(process.env.PORT || 3000, function () {
console.log("Listening on port " + process.env.PORT);
app.listen(port, function () {
console.log("Listening on port " + port);
if(process.env.NODE_ENV==='test') {
console.log('Running Tests...');
setTimeout(function () {
Expand Down

0 comments on commit 85bfa7b

Please sign in to comment.