URL shortener - application error deploying with heroku

Finished and works perfectly with cloud9.

But having trouble deploying with heroku. The error log is not descriptive at all:

2017-03-07T10:55:14.282664+00:00 heroku[web.1]: State changed from starting to crashed
2017-03-07T10:55:14.269831+00:00 heroku[web.1]: Process exited with status 1
2017-03-07T10:55:17.646187+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=fcc-shortenurl.herokuapp.com request_id=0a7b28a5-fdf3-4a88-971c-cecd748f1ea4 fwd="58.152.144.225" dyno= connect= service= status=503 bytes=
2017-03-07T10:55:19.254197+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=fcc-shortenurl.herokuapp.com request_id=164d5ff9-f0fc-43bd-a876-9ad5b507e42e fwd="58.152.144.225" dyno= connect= service= status=503 bytes=

Not sure what else to add since the log is not very useful. Any idea how to proceed?

The only change I’ve made to code before deploying is:

  • Changed to: app.listen(process.env.PORT)
  • Added to package.json:
    “scripts”: {
    “start”: “node server.js”
    }

It should be process.env.PORT

Sry, just a typo on my part. I have “process.env.PORT” in my code. This isn’t the issue.

Ok. I opened up Heroku toolbelt. The log is more descriptive:

2017-03-07T11:46:06.000000+00:00 app[api]: Build succeeded
2017-03-07T11:46:18.049037+00:00 heroku[web.1]: Starting process with command `npm start`
2017-03-07T11:46:21.016855+00:00 app[web.1]:
2017-03-07T11:46:21.016890+00:00 app[web.1]: > shorturl@1.0.0 start /app
2017-03-07T11:46:21.016891+00:00 app[web.1]: > node server.js
2017-03-07T11:46:21.016892+00:00 app[web.1]:
2017-03-07T11:46:21.233409+00:00 app[web.1]: module.js:471
2017-03-07T11:46:21.233412+00:00 app[web.1]:     throw err;
2017-03-07T11:46:21.233413+00:00 app[web.1]:     ^
2017-03-07T11:46:21.233413+00:00 app[web.1]:
2017-03-07T11:46:21.233414+00:00 app[web.1]: Error: Cannot find module 'mongodb'
2017-03-07T11:46:21.233415+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:469:15)
2017-03-07T11:46:21.233416+00:00 app[web.1]:     at Function.Module._load (module.js:417:25)
2017-03-07T11:46:21.233417+00:00 app[web.1]:     at Module.require (module.js:497:17)
2017-03-07T11:46:21.233417+00:00 app[web.1]:     at require (internal/module.js:20:19)
2017-03-07T11:46:21.233418+00:00 app[web.1]:     at Object.<anonymous> (/app/server.js:9:15)
2017-03-07T11:46:21.233419+00:00 app[web.1]:     at Module._compile (module.js:570:32)
2017-03-07T11:46:21.233419+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:579:10)
2017-03-07T11:46:21.233420+00:00 app[web.1]:     at Module.load (module.js:487:32)
2017-03-07T11:46:21.233422+00:00 app[web.1]:     at Function.Module._load (module.js:438:3)
2017-03-07T11:46:21.233421+00:00 app[web.1]:     at tryModuleLoad (module.js:446:12)
2017-03-07T11:46:21.244651+00:00 app[web.1]:
2017-03-07T11:46:21.252465+00:00 app[web.1]: npm ERR! Linux 3.13.0-110-generic
2017-03-07T11:46:21.252678+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2017-03-07T11:46:21.252831+00:00 app[web.1]: npm ERR! node v6.10.0
2017-03-07T11:46:21.253000+00:00 app[web.1]: npm ERR! npm  v3.10.10
2017-03-07T11:46:21.253133+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-03-07T11:46:21.253432+00:00 app[web.1]: npm ERR! shorturl@1.0.0 start: `node server.js`
2017-03-07T11:46:21.253824+00:00 app[web.1]: npm ERR! Failed at the shorturl@1.0.0 start script 'node server.js'.
2017-03-07T11:46:21.253559+00:00 app[web.1]: npm ERR! Exit status 1
2017-03-07T11:46:21.253973+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2017-03-07T11:46:21.253664+00:00 app[web.1]: npm ERR!
2017-03-07T11:46:21.254060+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the shorturl package,
2017-03-07T11:46:21.254142+00:00 app[web.1]: npm ERR! not with npm itself.
2017-03-07T11:46:21.254243+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2017-03-07T11:46:21.254330+00:00 app[web.1]: npm ERR!     node server.js
2017-03-07T11:46:21.254414+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2017-03-07T11:46:21.254500+00:00 app[web.1]: npm ERR!     npm bugs shorturl
2017-03-07T11:46:21.254622+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2017-03-07T11:46:21.254796+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-03-07T11:46:21.259433+00:00 app[web.1]:
2017-03-07T11:46:21.254706+00:00 app[web.1]: npm ERR!     npm owner ls shorturl
2017-03-07T11:46:21.259755+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2017-03-07T11:46:21.259684+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-03-07T11:46:21.428424+00:00 heroku[web.1]: Process exited with status 1
2017-03-07T11:46:21.458386+00:00 heroku[web.1]: State changed from starting to crashed
2017-03-07T11:46:21.459759+00:00 heroku[web.1]: State changed from crashed to starting
2017-03-07T11:46:22.970103+00:00 heroku[web.1]: Starting process with command `npm start`
2017-03-07T11:46:24.772464+00:00 app[web.1]: > shorturl@1.0.0 start /app
2017-03-07T11:46:24.772465+00:00 app[web.1]: > node server.js
2017-03-07T11:46:24.772452+00:00 app[web.1]:
2017-03-07T11:46:24.772466+00:00 app[web.1]:
2017-03-07T11:46:24.933486+00:00 app[web.1]: module.js:471
2017-03-07T11:46:24.933488+00:00 app[web.1]:     throw err;
2017-03-07T11:46:24.933489+00:00 app[web.1]:     ^
2017-03-07T11:46:24.933490+00:00 app[web.1]:
2017-03-07T11:46:24.933490+00:00 app[web.1]: Error: Cannot find module 'mongodb'
2017-03-07T11:46:24.933491+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:469:15)
2017-03-07T11:46:24.933491+00:00 app[web.1]:     at Function.Module._load (module.js:417:25)
2017-03-07T11:46:24.933492+00:00 app[web.1]:     at require (internal/module.js:20:19)
2017-03-07T11:46:24.933492+00:00 app[web.1]:     at Module.require (module.js:497:17)
2017-03-07T11:46:24.933492+00:00 app[web.1]:     at Object.<anonymous> (/app/server.js:9:15)
2017-03-07T11:46:24.933493+00:00 app[web.1]:     at Module._compile (module.js:570:32)
2017-03-07T11:46:24.933493+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:579:10)
2017-03-07T11:46:24.933494+00:00 app[web.1]:     at Module.load (module.js:487:32)
2017-03-07T11:46:24.933494+00:00 app[web.1]:     at tryModuleLoad (module.js:446:12)
2017-03-07T11:46:24.933495+00:00 app[web.1]:     at Function.Module._load (module.js:438:3)
2017-03-07T11:46:24.939990+00:00 app[web.1]:
2017-03-07T11:46:24.947007+00:00 app[web.1]: npm ERR! Linux 3.13.0-110-generic
2017-03-07T11:46:24.947262+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2017-03-07T11:46:24.947493+00:00 app[web.1]: npm ERR! node v6.10.0
2017-03-07T11:46:24.947684+00:00 app[web.1]: npm ERR! npm  v3.10.10
2017-03-07T11:46:24.947875+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-03-07T11:46:24.948144+00:00 app[web.1]: npm ERR! shorturl@1.0.0 start: `node server.js`
2017-03-07T11:46:24.948285+00:00 app[web.1]: npm ERR! Exit status 1
2017-03-07T11:46:24.948434+00:00 app[web.1]: npm ERR!
2017-03-07T11:46:24.948572+00:00 app[web.1]: npm ERR! Failed at the shorturl@1.0.0 start script 'node server.js'.
2017-03-07T11:46:24.948707+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2017-03-07T11:46:24.948854+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the shorturl package,
2017-03-07T11:46:24.949131+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2017-03-07T11:46:24.949265+00:00 app[web.1]: npm ERR!     node server.js
2017-03-07T11:46:24.948988+00:00 app[web.1]: npm ERR! not with npm itself.
2017-03-07T11:46:24.949401+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2017-03-07T11:46:24.949534+00:00 app[web.1]: npm ERR!     npm bugs shorturl
2017-03-07T11:46:24.949666+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2017-03-07T11:46:24.949789+00:00 app[web.1]: npm ERR!     npm owner ls shorturl
2017-03-07T11:46:24.949919+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-03-07T11:46:24.953291+00:00 app[web.1]:
2017-03-07T11:46:24.953488+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-03-07T11:46:24.953602+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2017-03-07T11:46:25.024766+00:00 heroku[web.1]: State changed from starting to crashed
2017-03-07T11:46:25.010667+00:00 heroku[web.1]: Process exited with status 1
2017-03-07T11:46:26.211765+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=fcc-shortenurl.herokuapp.com request_id=21e6e167-93a2-4b59-a9d0-525797f5bcdc fwd="58.152.144.225" dyno= connect= service= status=503 bytes=
2017-03-07T11:46:27.767804+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=fcc-shortenurl.herokuapp.com request_id=58ced9be-dca0-47b9-a1be-6bc0ab884371 fwd="58.152.144.225" dyno= connect= service= status=503 bytes=

Do you have your code on GitHub or something?

Yes. Please ignore the security issue with user:password, trying to debug this and disabled .env.

You forgot to add mongodb as a dependency in package.json.

1 Like

Finally! Works now. Thanks.

Quick question - If I left out the dependency, why would it work with cloud9 and not heroku then?

I suppose mongodb was already downloaded to your local node_modules folder.