5

I have attempted to put together a sample node.js app on Heroku basically as per their instructions here: https://devcenter.heroku.com/articles/nodejs

The app runs fine locally with foreman start, however, each time I deploy the app it crashes. What am I doing wrong?

My Procfile contains:

web: node web.js

My package.json contains:

{
  "name": "testapp",
  "version": "0.0.1",
  "engines": {
      "node": "0.6.15"
    , "npm": "1.1.9"    
  }
  , "dependencies": {
    "tower": "0.4.0-12"
  }
}

My web.js contains:

var express = require('express');

var app = express.createServer(express.logger());

app.get('/', function(request, response) {
  response.send('Hello World!');
});

var port = process.env.PORT || 3000;
app.listen(port, function() {
  console.log("Listening on " + port);
});

The app deploys and starts up, yet crashes each time. The log output I see from the app is:

2012-04-27T20:21:31+00:00 heroku[web.1]: State changed from created to starting
2012-04-27T20:21:37+00:00 heroku[web.1]: Starting process with command `node web.js`
2012-04-27T20:21:38+00:00 app[web.1]: 
2012-04-27T20:21:38+00:00 app[web.1]: node.js:201
2012-04-27T20:21:38+00:00 app[web.1]:         throw e; // process.nextTick error, or 'error' event on first tick
2012-04-27T20:21:38+00:00 app[web.1]:               ^
2012-04-27T20:21:38+00:00 app[web.1]: Error: Cannot find module 'express'
2012-04-27T20:21:38+00:00 app[web.1]:     at Function._resolveFilename (module.js:332:11)
2012-04-27T20:21:38+00:00 app[web.1]:     at Function._load (module.js:279:25)
2012-04-27T20:21:38+00:00 app[web.1]:     at Module.require (module.js:354:17)
2012-04-27T20:21:38+00:00 app[web.1]:     at require (module.js:370:17)
2012-04-27T20:21:38+00:00 app[web.1]:     at Object.<anonymous> (/app/web.js:1:77)
2012-04-27T20:21:38+00:00 app[web.1]:     at Module._compile (module.js:441:26)
2012-04-27T20:21:38+00:00 app[web.1]:     at Object..js (module.js:459:10)
2012-04-27T20:21:38+00:00 app[web.1]:     at Module.load (module.js:348:31)
2012-04-27T20:21:38+00:00 app[web.1]:     at Function._load (module.js:308:12)
2012-04-27T20:21:38+00:00 app[web.1]:     at Array.0 (module.js:479:10)
2012-04-27T20:21:39+00:00 heroku[web.1]: Process exited with status 1
2012-04-27T20:21:40+00:00 heroku[web.1]: State changed from starting to crashed
2012-04-27T20:30:01+00:00 heroku[router]: Error H10 (App crashed) -> GET testapp.herokuapp.com/ dyno= queue= wait= service= status=503 bytes=

3 Answers 3

10

It appears you are requiring express in your web.js, so why you do not add express to your dependencies? Your local copy may have express installed already, that's why you are not getting any error. Tower may require express, however, you cannot directly access express from it, it is a submodule in tower's directories, not in your app directory.

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

3 Comments

Interesting. It was not required locally to execute properly, however this did indeed do the trick. Any idea as to the differential of local vs remote heroku in this case? Additionally, how do you quickly the list of version information to add to package.json normally, simply npm ls? Trying to get an idea of efficiently assembling a package.json.
maybe your express installed globally in your computer? npm install express -g does that. npm ls is fine, I use package.json.nodejitsu.com as a reference for my package.json assembling
+1 for me this was also the reason my app would not run on heroku. I did not have all required modules listed as dependencies in package.json
0

In the past this was a problem with a version of npm. I would recommend upgrading to the latest version and reinstalling at least express.

Comments

0

Check that you don't have express defined under devDependencies in package.json. If you do, even running npm install express --save will not move it to dependencies.

I had this issue with Vue.js project created with vue-cli, which added the express dep under devDependencies.

Comments

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.