0

Here's my app app.js:

var express=        require("express");

var app=    express();
app.get('/',function(req,res){
    console.log(req);
    res.send("Hello world");
});

app.get('*', function(req, res){
  res.send("Nothing to see here.", 404);
});

var port=   process.env.PORT || 3000;
app.listen(port,function(){
    var host=   server.address().address;
    var port=   server.address().port;
});

When I run nodejs app.js locally, this works as intended. I can go to localhost:3000 and see Hello world, but when I push this to Heroku, I get this in my log:

2016-10-25T03:37:09.449732+00:00 heroku[web.1]: Starting process with command `node app.js`
2016-10-25T03:37:11.207319+00:00 app[web.1]: /app/app.js:47
2016-10-25T03:37:11.207341+00:00 app[web.1]:    var host=   server.address().address;
2016-10-25T03:37:11.207342+00:00 app[web.1]:                                ^
2016-10-25T03:37:11.207343+00:00 app[web.1]: 
2016-10-25T03:37:11.207343+00:00 app[web.1]: ReferenceError: server is not defined
2016-10-25T03:37:11.207344+00:00 app[web.1]:     at Server.<anonymous> (/app/app.js:47:28)
2016-10-25T03:37:11.207345+00:00 app[web.1]:     at Server.g (events.js:291:16)
2016-10-25T03:37:11.207345+00:00 app[web.1]:     at emitNone (events.js:86:13)
2016-10-25T03:37:11.207346+00:00 app[web.1]:     at Server.emit (events.js:185:7)
2016-10-25T03:37:11.207346+00:00 app[web.1]:     at emitListeningNT (net.js:1278:10)
2016-10-25T03:37:11.207347+00:00 app[web.1]:     at _combinedTickCallback (internal/process/next_tick.js:71:11)
2016-10-25T03:37:11.207348+00:00 app[web.1]:     at process._tickCallback (internal/process/next_tick.js:98:9)
2016-10-25T03:37:11.207349+00:00 app[web.1]:     at Module.runMain (module.js:592:11)
2016-10-25T03:37:11.207349+00:00 app[web.1]:     at run (bootstrap_node.js:394:7)
2016-10-25T03:37:11.207350+00:00 app[web.1]:     at startup (bootstrap_node.js:149:9)
2016-10-25T03:37:11.287706+00:00 heroku[web.1]: State changed from starting to crashed
2016-10-25T03:37:11.290415+00:00 heroku[web.1]: Process exited with status 1

What's going on here?

1 Answer 1

3

What you've shown here has no variable 'server' defined. No idea why it's working locally, but there's no reason it should work.

Post your full app.js and your package.json, that may help us get more specific.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, I forgot to define the server variable as the app.listen() function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.