Trouble transferring from local to Heroku /w MongoDB

Hello all.

I’ve just finished creating the url shortener web application for the back end certification. However, before I can mark the challenge, I need to deploy it to heroku. Upon deployment, the Heroku app fails to load (even my views page for instructions), even though it worked for me locally. I suspect this is an issue with my setup of MongoDB but I’m entirely lost. Below I have pasted my github link and my Heroku logs upon deployment. Any help is appreciated.

Github Project

Nicks-MacBook-Pro-2:url-shortener Nick$ heroku open
Nicks-MacBook-Pro-2:url-shortener Nick$ heroku logs
2017-05-01T04:27:10.889333+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=janne-short.herokuapp.com request_id=3d7557ec-8a06-4dc7-b844-1b0126394cf2 fwd="74.104.168.246" dyno= connect= service= status=503 bytes= protocol=https
2017-05-01T04:30:26.088834+00:00 heroku[web.1]: State changed from crashed to starting
2017-05-01T04:30:27.838387+00:00 heroku[web.1]: Starting process with command `node ./bin/www`
2017-05-01T04:30:30.897144+00:00 heroku[web.1]: Process exited with status 1
2017-05-01T04:30:30.800392+00:00 app[web.1]:       throw er; // Unhandled 'error' event
2017-05-01T04:30:30.800393+00:00 app[web.1]:       ^
2017-05-01T04:30:30.800378+00:00 app[web.1]: 
2017-05-01T04:30:30.801323+00:00 app[web.1]: MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
2017-05-01T04:30:30.800391+00:00 app[web.1]: events.js:160
2017-05-01T04:30:30.801324+00:00 app[web.1]:     at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:328:35)
2017-05-01T04:30:30.801325+00:00 app[web.1]:     at emitOne (events.js:96:13)
2017-05-01T04:30:30.801326+00:00 app[web.1]:     at Pool.emit (events.js:188:7)
2017-05-01T04:30:30.801329+00:00 app[web.1]:     at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:177:49)
2017-05-01T04:30:30.801326+00:00 app[web.1]:     at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:274:12)
2017-05-01T04:30:30.801327+00:00 app[web.1]:     at Connection.g (events.js:291:16)
2017-05-01T04:30:30.801329+00:00 app[web.1]:     at Socket.g (events.js:291:16)
2017-05-01T04:30:30.801327+00:00 app[web.1]:     at emitTwo (events.js:106:13)
2017-05-01T04:30:30.801330+00:00 app[web.1]:     at emitOne (events.js:96:13)
2017-05-01T04:30:30.801330+00:00 app[web.1]:     at Socket.emit (events.js:188:7)
2017-05-01T04:30:30.801328+00:00 app[web.1]:     at Connection.emit (events.js:191:7)
2017-05-01T04:30:30.801331+00:00 app[web.1]:     at emitErrorNT (net.js:1281:8)
2017-05-01T04:30:30.801332+00:00 app[web.1]:     at _combinedTickCallback (internal/process/next_tick.js:80:11)
2017-05-01T04:30:30.801332+00:00 app[web.1]:     at process._tickCallback (internal/process/next_tick.js:104:9)
2017-05-01T04:30:30.913006+00:00 heroku[web.1]: State changed from starting to crashed
2017-05-01T04:30:30.914102+00:00 heroku[web.1]: State changed from crashed to starting
2017-05-01T04:30:32.527515+00:00 heroku[web.1]: Starting process with command `node ./bin/www`
2017-05-01T04:30:35.553157+00:00 app[web.1]: 
2017-05-01T04:30:35.554938+00:00 app[web.1]:     at emitTwo (events.js:106:13)
2017-05-01T04:30:35.553210+00:00 app[web.1]: events.js:160
2017-05-01T04:30:35.554938+00:00 app[web.1]:     at Connection.emit (events.js:191:7)
2017-05-01T04:30:35.553212+00:00 app[web.1]:       ^
2017-05-01T04:30:35.554939+00:00 app[web.1]:     at Socket.g (events.js:291:16)
2017-05-01T04:30:35.553211+00:00 app[web.1]:       throw er; // Unhandled 'error' event
2017-05-01T04:30:35.554939+00:00 app[web.1]:     at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:177:49)
2017-05-01T04:30:35.554932+00:00 app[web.1]: MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
2017-05-01T04:30:35.554940+00:00 app[web.1]:     at emitOne (events.js:96:13)
2017-05-01T04:30:35.554935+00:00 app[web.1]:     at emitOne (events.js:96:13)
2017-05-01T04:30:35.554941+00:00 app[web.1]:     at emitErrorNT (net.js:1281:8)
2017-05-01T04:30:35.554934+00:00 app[web.1]:     at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:328:35)
2017-05-01T04:30:35.554941+00:00 app[web.1]:     at Socket.emit (events.js:188:7)
2017-05-01T04:30:35.554936+00:00 app[web.1]:     at Pool.emit (events.js:188:7)
2017-05-01T04:30:35.554942+00:00 app[web.1]:     at _combinedTickCallback (internal/process/next_tick.js:80:11)
2017-05-01T04:30:35.554936+00:00 app[web.1]:     at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:274:12)
2017-05-01T04:30:35.554943+00:00 app[web.1]:     at process._tickCallback (internal/process/next_tick.js:104:9)
2017-05-01T04:30:35.554937+00:00 app[web.1]:     at Connection.g (events.js:291:16)
2017-05-01T04:30:35.653066+00:00 heroku[web.1]: State changed from starting to crashed
2017-05-01T04:30:35.639242+00:00 heroku[web.1]: Process exited with status 1
2017-05-01T04:30:36.220868+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=janne-short.herokuapp.com request_id=79e766e8-6a60-4c6b-9ed9-4d3f865cd2b0 fwd="74.104.168.246" dyno= connect= service= status=503 bytes= protocol=https
2017-05-01T04:30:37.081378+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=janne-short.herokuapp.com request_id=1885abbb-8b76-42a6-bbf0-8bbe6fa192b1 fwd="74.104.168.246" dyno= connect= service= status=503 bytes= protocol=https
2017-05-01T04:32:54.355082+00:00 heroku[web.1]: State changed from crashed to starting
2017-05-01T04:32:55.838533+00:00 heroku[web.1]: Starting process with command `npm start`
2017-05-01T04:32:57.648426+00:00 app[web.1]: 
2017-05-01T04:32:57.648441+00:00 app[web.1]: > url-shortener@0.0.0 start /app
2017-05-01T04:32:57.648441+00:00 app[web.1]: > node ./bin/www
2017-05-01T04:32:57.648442+00:00 app[web.1]: 
2017-05-01T04:32:58.273212+00:00 app[web.1]:       throw er; // Unhandled 'error' event
2017-05-01T04:32:58.273918+00:00 app[web.1]: MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
2017-05-01T04:32:58.273197+00:00 app[web.1]: 
2017-05-01T04:32:58.273209+00:00 app[web.1]: events.js:160
2017-05-01T04:32:58.273921+00:00 app[web.1]:     at Pool.emit (events.js:188:7)
2017-05-01T04:32:58.273212+00:00 app[web.1]:       ^
2017-05-01T04:32:58.273922+00:00 app[web.1]:     at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:274:12)
2017-05-01T04:32:58.273922+00:00 app[web.1]:     at Connection.g (events.js:291:16)
2017-05-01T04:32:58.273920+00:00 app[web.1]:     at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:328:35)
2017-05-01T04:32:58.273921+00:00 app[web.1]:     at emitOne (events.js:96:13)
2017-05-01T04:32:58.273924+00:00 app[web.1]:     at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:177:49)
2017-05-01T04:32:58.273925+00:00 app[web.1]:     at emitOne (events.js:96:13)
2017-05-01T04:32:58.273923+00:00 app[web.1]:     at emitTwo (events.js:106:13)
2017-05-01T04:32:58.273928+00:00 app[web.1]:     at _combinedTickCallback (internal/process/next_tick.js:80:11)
2017-05-01T04:32:58.273929+00:00 app[web.1]:     at process._tickCallback (internal/process/next_tick.js:104:9)
2017-05-01T04:32:58.283068+00:00 app[web.1]: 
2017-05-01T04:32:58.273924+00:00 app[web.1]:     at Connection.emit (events.js:191:7)
2017-05-01T04:32:58.273925+00:00 app[web.1]:     at Socket.g (events.js:291:16)
2017-05-01T04:32:58.273926+00:00 app[web.1]:     at Socket.emit (events.js:188:7)
2017-05-01T04:32:58.291878+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2017-05-01T04:32:58.273927+00:00 app[web.1]:     at emitErrorNT (net.js:1281:8)
2017-05-01T04:32:58.292385+00:00 app[web.1]: npm ERR! url-shortener@0.0.0 start: `node ./bin/www`
2017-05-01T04:32:58.291662+00:00 app[web.1]: npm ERR! Linux 3.13.0-112-generic
2017-05-01T04:32:58.292570+00:00 app[web.1]: npm ERR! 
2017-05-01T04:32:58.292034+00:00 app[web.1]: npm ERR! node v6.10.2
2017-05-01T04:32:58.292156+00:00 app[web.1]: npm ERR! npm  v3.10.10
2017-05-01T04:32:58.292661+00:00 app[web.1]: npm ERR! Failed at the url-shortener@0.0.0 start script 'node ./bin/www'.
2017-05-01T04:32:58.292283+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-05-01T04:32:58.292745+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2017-05-01T04:32:58.292470+00:00 app[web.1]: npm ERR! Exit status 1
2017-05-01T04:32:58.292946+00:00 app[web.1]: npm ERR! not with npm itself.
2017-05-01T04:32:58.292835+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the url-shortener package,
2017-05-01T04:32:58.293483+00:00 app[web.1]: npm ERR!     npm bugs url-shortener
2017-05-01T04:32:58.293098+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2017-05-01T04:32:58.293229+00:00 app[web.1]: npm ERR!     node ./bin/www
2017-05-01T04:32:58.293358+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2017-05-01T04:32:58.293723+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2017-05-01T04:32:58.293827+00:00 app[web.1]: npm ERR!     npm owner ls url-shortener
2017-05-01T04:32:58.293954+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-05-01T04:32:58.298108+00:00 app[web.1]: 
2017-05-01T04:32:58.298516+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2017-05-01T04:32:58.298384+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-05-01T04:32:58.393975+00:00 heroku[web.1]: State changed from starting to crashed
2017-05-01T04:32:58.377364+00:00 heroku[web.1]: Process exited with status 1
2017-05-01T04:33:00.730604+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=janne-short.herokuapp.com request_id=88b5032b-e350-44fb-bf7b-73082b862628 fwd="74.104.168.246" dyno= connect= service= status=503 bytes= protocol=https
2017-05-01T04:33:01.584144+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=janne-short.herokuapp.com request_id=8797ff25-264d-415c-86c2-1c0fa8829e58 fwd="74.104.168.246" dyno= connect= service= status=503 bytes= protocol=https
Nicks-MacBook-Pro-2:url-shortener Nick$ 

I think this is the problem.

You had the db local during development (127.0.0.1 - localhost ip address), so now you need to setup a db for production.
mLab provides a free mongodb https://mlab.com/

Get an account and change the connection string to the db you create on mLab. When you make the db, you will also have to create a user account for the db to be able to access it (seperate from the mLab account).

@sfallmann

Ok so I understand what you’re saying, but I don’t understand how to do what you’re saying. I went to the mlab website and created a new database but when I looked up how to connect a database with mLab, the instructions are not applicable to me because what the instructions say are not what appear on my screen. What do you recommend I do?

I’m not sure where you are running afoul in the instructions.

When you create the db, you should be able to click on it and above it should be the connection string info. You also have to make a db user to connect to the db and substitute the username and password in the appropriate spot within the provided connection string.

I looked at your repo for this project and found this in routes/index.js:

mongoose.connect(process.env.MONGODB_URI || process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://localhost/short_urls');

According to your code, you need to set the Heroku environment variable MONGOLAB_URI to the string
Right now, since all of the environment variables are empty, the last value for the localhost connection string is used.

Heroku - Configuration and Config Vars

@sfallmann

What I mean to say I understand the instructions, but the instructions don’t match up with what’s on my screen. I do not have the connection string info when I log into the site, so I’m not entirely sure what to do. Additionally, how would I go about setting the Heroku environment variable MONGOLAB_URI

Here’s a screenshot of my page:

See here to set up heroku env variables . https://devcenter.heroku.com/articles/heroku-local#set-up-your-local-environment-variables

You can also do it like so -

Create MongoDB Deployments like so

@yasserhussain1110

The Heroku variables make sense, however I still don’t understand how to connect to the database. I have a similar screen to the one you have, however I do not know how to connect to the database or get the url to the database for my app.

EDIT: I just figured out that I was creating the wrong kind of database I was creating a private environment instead. I’ll stay updated on the progress.

@yasserhussain1110 @sfallmann

So I applied the changes both of you provided me and it worked, well for a little bit. I was able to reach the homepage, and I was able to generate one short URL, however when I tried to go to that short URL something failed and the project broke again. I’ve pasted my console dump below but I think it has to do with an error it has reading the database.

2017-05-01T14:01:54.255301+00:00 app[web.1]:     at _combinedTickCallback (internal/process/next_tick.js:73:7)
2017-05-01T14:01:54.272493+00:00 app[web.1]: npm ERR! url-shortener@0.0.0 start: `node ./bin/www`
2017-05-01T14:01:54.264034+00:00 app[web.1]: 
2017-05-01T14:01:54.259123+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/favicon.ico" host=janne-short.herokuapp.com request_id=afd92ab5-93e3-4637-b109-1596c481edaf fwd="50.207.137.226" dyno=web.1 connect=0ms service=56ms status=503 bytes=0 protocol=https
2017-05-01T14:01:54.255300+00:00 app[web.1]:     at /app/node_modules/kareem/index.js:131:16
2017-05-01T14:01:54.271448+00:00 app[web.1]: npm ERR! Linux 3.13.0-112-generic
2017-05-01T14:01:54.271724+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2017-05-01T14:01:54.271946+00:00 app[web.1]: npm ERR! node v6.10.2
2017-05-01T14:01:54.255301+00:00 app[web.1]:     at process._tickCallback (internal/process/next_tick.js:104:9)
2017-05-01T14:01:54.272911+00:00 app[web.1]: npm ERR! Failed at the url-shortener@0.0.0 start script 'node ./bin/www'.
2017-05-01T14:01:54.272339+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-05-01T14:01:54.272148+00:00 app[web.1]: npm ERR! npm  v3.10.10
2017-05-01T14:01:54.272773+00:00 app[web.1]: npm ERR! 
2017-05-01T14:01:54.274108+00:00 app[web.1]: npm ERR!     npm owner ls url-shortener
2017-05-01T14:01:54.273046+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2017-05-01T14:01:54.282481+00:00 app[web.1]: 
2017-05-01T14:01:54.272630+00:00 app[web.1]: npm ERR! Exit status 1
2017-05-01T14:01:54.273963+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2017-05-01T14:01:54.273174+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the url-shortener package,
2017-05-01T14:01:54.282830+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2017-05-01T14:01:54.273305+00:00 app[web.1]: npm ERR! not with npm itself.
2017-05-01T14:01:54.282713+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-05-01T14:01:54.273443+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2017-05-01T14:01:54.273576+00:00 app[web.1]: npm ERR!     node ./bin/www
2017-05-01T14:01:54.274227+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-05-01T14:01:54.273706+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2017-05-01T14:01:54.273833+00:00 app[web.1]: npm ERR!     npm bugs url-shortener
2017-05-01T14:01:54.358420+00:00 heroku[web.1]: State changed from up to crashed
2017-05-01T14:01:54.360070+00:00 heroku[web.1]: State changed from crashed to starting
2017-05-01T14:01:54.348389+00:00 heroku[web.1]: Process exited with status 1
2017-05-01T14:01:56.446653+00:00 heroku[web.1]: Starting process with command `npm start`
2017-05-01T14:01:59.384698+00:00 app[web.1]: 
2017-05-01T14:01:59.384714+00:00 app[web.1]: > url-shortener@0.0.0 start /app
2017-05-01T14:01:59.384715+00:00 app[web.1]: > node ./bin/www
2017-05-01T14:01:59.384716+00:00 app[web.1]: 
2017-05-01T14:02:00.109526+00:00 heroku[web.1]: State changed from starting to up
2017-05-01T14:02:07.401477+00:00 app[web.1]: (node:17) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html
2017-05-01T14:02:07.405089+00:00 app[web.1]: GET /new/www.cnn.com 200 32.946 ms - 55
2017-05-01T14:02:07.402896+00:00 heroku[router]: at=info method=GET path="/new/www.cnn.com" host=janne-short.herokuapp.com request_id=6db02544-2f97-4b7f-a0c0-0bb44c7224b3 fwd="50.207.137.226" dyno=web.1 connect=1ms service=60ms status=200 bytes=294 protocol=https
2017-05-01T14:02:07.962451+00:00 app[web.1]: Error: Can't set headers after they are sent.
2017-05-01T14:02:07.962463+00:00 app[web.1]:     at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:357:11)
2017-05-01T14:02:07.962463+00:00 app[web.1]:     at ServerResponse.header (/app/node_modules/express/lib/response.js:725:10)
2017-05-01T14:02:07.962464+00:00 app[web.1]:     at ServerResponse.send (/app/node_modules/express/lib/response.js:170:12)
2017-05-01T14:02:07.962487+00:00 app[web.1]:     at done (/app/node_modules/express/lib/response.js:962:10)
2017-05-01T14:02:07.962488+00:00 app[web.1]:     at Object.exports.renderFile (/app/node_modules/jade/lib/index.js:374:12)
2017-05-01T14:02:07.962489+00:00 app[web.1]:     at View.exports.__express [as engine] (/app/node_modules/jade/lib/index.js:417:11)
2017-05-01T14:02:07.962490+00:00 app[web.1]:     at View.render (/app/node_modules/express/lib/view.js:128:8)
2017-05-01T14:02:07.962491+00:00 app[web.1]:     at tryRender (/app/node_modules/express/lib/application.js:640:10)
2017-05-01T14:02:07.962491+00:00 app[web.1]:     at EventEmitter.render (/app/node_modules/express/lib/application.js:592:3)
2017-05-01T14:02:07.962492+00:00 app[web.1]:     at ServerResponse.render (/app/node_modules/express/lib/response.js:966:7)
2017-05-01T14:02:07.962493+00:00 app[web.1]:     at /app/app.js:43:7
2017-05-01T14:02:07.962494+00:00 app[web.1]:     at Layer.handle_error (/app/node_modules/express/lib/router/layer.js:71:5)
2017-05-01T14:02:07.962494+00:00 app[web.1]:     at trim_prefix (/app/node_modules/express/lib/router/index.js:315:13)
2017-05-01T14:02:07.962495+00:00 app[web.1]:     at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
2017-05-01T14:02:07.962495+00:00 app[web.1]:     at /app/node_modules/express/lib/router/index.js:284:7
2017-05-01T14:02:07.962496+00:00 app[web.1]:     at next (/app/node_modules/express/lib/router/index.js:275:10)
2017-05-01T14:02:08.040025+00:00 app[web.1]: events.js:160
2017-05-01T14:02:08.040027+00:00 app[web.1]:       throw er; // Unhandled 'error' event
2017-05-01T14:02:08.040028+00:00 app[web.1]:       ^
2017-05-01T14:02:08.040029+00:00 app[web.1]: 
2017-05-01T14:02:08.040030+00:00 app[web.1]: TypeError: Cannot read property 'original_url' of null
2017-05-01T14:02:08.040030+00:00 app[web.1]:     at /app/routes/index.js:33:24
2017-05-01T14:02:08.040031+00:00 app[web.1]:     at Query.<anonymous> (/app/node_modules/mongoose/lib/model.js:3731:16)
2017-05-01T14:02:08.040032+00:00 app[web.1]:     at /app/node_modules/kareem/index.js:277:21
2017-05-01T14:02:08.040033+00:00 app[web.1]:     at /app/node_modules/kareem/index.js:131:16
2017-05-01T14:02:08.040033+00:00 app[web.1]:     at _combinedTickCallback (internal/process/next_tick.js:73:7)
2017-05-01T14:02:08.040041+00:00 app[web.1]:     at process._tickCallback (internal/process/next_tick.js:104:9)
2017-05-01T14:02:08.052614+00:00 app[web.1]: 
2017-05-01T14:02:08.062089+00:00 app[web.1]: npm ERR! Linux 3.13.0-112-generic
2017-05-01T14:02:08.062374+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2017-05-01T14:02:08.062606+00:00 app[web.1]: npm ERR! node v6.10.2
2017-05-01T14:02:08.062816+00:00 app[web.1]: npm ERR! npm  v3.10.10
2017-05-01T14:02:08.063016+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-05-01T14:02:08.063173+00:00 app[web.1]: npm ERR! url-shortener@0.0.0 start: `node ./bin/www`
2017-05-01T14:02:08.063306+00:00 app[web.1]: npm ERR! Exit status 1
2017-05-01T14:02:08.063458+00:00 app[web.1]: npm ERR! 
2017-05-01T14:02:08.063603+00:00 app[web.1]: npm ERR! Failed at the url-shortener@0.0.0 start script 'node ./bin/www'.
2017-05-01T14:02:08.063734+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2017-05-01T14:02:08.063871+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the url-shortener package,
2017-05-01T14:02:08.064002+00:00 app[web.1]: npm ERR! not with npm itself.
2017-05-01T14:02:08.064138+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2017-05-01T14:02:08.064275+00:00 app[web.1]: npm ERR!     node ./bin/www
2017-05-01T14:02:08.064409+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2017-05-01T14:02:08.064540+00:00 app[web.1]: npm ERR!     npm bugs url-shortener
2017-05-01T14:02:08.064674+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2017-05-01T14:02:08.064802+00:00 app[web.1]: npm ERR!     npm owner ls url-shortener
2017-05-01T14:02:08.064937+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-05-01T14:02:08.074290+00:00 app[web.1]: 
2017-05-01T14:02:08.075191+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-05-01T14:02:08.075192+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2017-05-01T14:02:08.162686+00:00 heroku[web.1]: State changed from up to crashed
2017-05-01T14:02:08.046796+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/favicon.ico" host=janne-short.herokuapp.com request_id=d52dcf4f-edec-46b7-a19e-0fae495f11d0 fwd="50.207.137.226" dyno=web.1 connect=1ms service=56ms status=503 bytes=0 protocol=https
2017-05-01T14:02:08.149074+00:00 heroku[web.1]: Process exited with status 1
2017-05-01T14:02:23.033002+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/1797947795" host=janne-short.herokuapp.com request_id=0901db4a-9d21-44f0-9850-d5e427376eef fwd="50.207.137.226" dyno= connect= service= status=503 bytes= protocol=https
2017-05-01T14:02:23.691391+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=janne-short.herokuapp.com request_id=38d42f52-ee3a-4a99-893d-1942b2374681 fwd="50.207.137.226" dyno= connect= service= status=503 bytes= protocol=https
2017-05-01T14:02:31.579082+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/1797947795" host=janne-short.herokuapp.com request_id=6d7895e7-296d-474b-ba68-57a3a97b4e1d fwd="50.207.137.226" dyno= connect= service= status=503 bytes= protocol=https
2017-05-01T14:02:31.957221+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=janne-short.herokuapp.com request_id=5c99ccca-a4cf-4bf8-97e1-5daee959edfc fwd="50.207.137.226" dyno= connect= service= status=503 bytes= protocol=https
2017-05-01T14:02:44.926917+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=janne-short.herokuapp.com request_id=6523f700-ce42-48e2-988d-54311fcf4356 fwd="50.207.137.226" dyno= connect= service= status=503 bytes= protocol=https
2017-05-01T14:02:45.653609+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=janne-short.herokuapp.com request_id=ef8e0362-763c-45dc-b341-46b77c0728a1 fwd="50.207.137.226" dyno= connect= service= status=503 bytes= protocol=https
2017-05-01T14:02:58.628336+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=janne-short.herokuapp.com request_id=5c0c19da-1e1e-4cae-99a7-4c12ae57f35b fwd="50.207.137.226" dyno= connect= service= status=503 bytes= protocol=https
2017-05-01T14:02:59.463032+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=janne-short.herokuapp.com request_id=1e6bd9a1-e4d7-4d18-be2d-90ccb61daca6 fwd="50.207.137.226" dyno= connect= service= status=503 bytes= protocol=https

You’ll need to debug this. Its hard to say what went wrong just by looking at this log.

TypeError: Cannot read property ‘original_url’ of null

This error line is of interest.

Use console.log to check why the value is null.

I just looked at your github.
Use .gitignore to ignore -
node_modules & npm-debug.log

You have added .gitignore. But the point of .gitignore is that we don’t want to track node_modules and debug log with git.

We only track the primary source code via git. Anything which can be generated is not tracked.
All the libs within node_modules are sort of “generated” because they are already specified by your package.json file.

So now run these commands -

git rm node_modules/ -r
git rm npm-debug.log
git commit -am "Removed dependencies"
git push -u origin master

This will remove those from git.

1 Like

@yasserhussain1110 I did what you said. I tried running it locally again to log out any problems and the weird this is that it works locally with 0 changes but it does not work when I try it on heroku. Does this narrow down my options of problems?

Checking local logs won’t help. Run it in production and check the production logs. Clearly this issue is related with your app setup and not your code logic, because it works locally.