app not defined error while deploying through modulus

2.6k Views Asked by At

While trying to deploy my node app using modulus, I encounter the error message

ReferenceError: app is not defined
    at Object.<anonymous> (/mnt/app/index.js:1:63)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.runMain (module.js:575:10)
    at run (node.js:348:7)
    at startup (node.js:140:9)
    at node.js:463:3

index.js:

var express = require('express');
var app = express();

app.get('/hello', function(req, res) {
    console.log("World!!");
})

Express.js has been installed and added to "dependencies" in package.json

"dependencies": {
    "express": "^4.14.0"
  }

What could be the probable cause for the Error.

1

There are 1 best solutions below

0
Arun George On BEST ANSWER
app.listen(process.env.PORT || 3000);

Missed out on listening to the environment variable PORT that is causing the issue.