Use Heroku addon mongolab with node.js - node.js

I am using node.js with mongo lab and I have followed the mongolab tutorial (https://devcenter.heroku.com/articles/mongolab#getting-your-connection-uri) to change my url of db like this in my code:
module.exports = new Db(settings.db, new Server('mongodb://heroku_app3178:e6dd5g3btvanua3gfbmk6#ds051740.mongolab.com', 51740, {}), {safe: true});
I tested with local run, and I indeed see node is trying to connect to this new URL.
But when I deploy to Heroku. Heroku always complain about this.
I tried different things for 3 hours got no clue.
This is my log, could you please help?
2014-11-20T06:35:55.290572+00:00 heroku[api]: Release v17 created by abcc#gmail.com
2014-11-20T06:35:57.385492+00:00 heroku[web.1]: Starting process with command `node app.js`
2014-11-20T06:35:58.836675+00:00 heroku[web.1]: State changed from starting to up
2014-11-20T06:35:59.876883+00:00 app[web.1]: app.usr local
2014-11-20T06:36:00.396662+00:00 app[web.1]: at Socket.emit (events.js:95:17)a
2014-11-20T06:36:00.394396+00:00 app[web.1]:
2014-11-20T06:36:00.396664+00:00 app[web.1]: at net.js:440:14
2014-11-20T06:36:00.394894+00:00 app[web.1]: throw err;
2014-11-20T06:36:00.396665+00:00 app[web.1]: at process._tickCallback (node.js:419:13)
2014-11-20T06:36:00.396651+00:00 app[web.1]: Error: Error connecting to database: failed to connect to [127.0.0.1:27017] ====> why is this? so confused
2014-11-20T06:36:00.394918+00:00 app[web.1]: ^
2014-11-20T06:36:00.396654+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/server.js:553:74)
2014-11-20T06:36:00.396656+00:00 app[web.1]: at emit (events.js:106:17)
2014-11-20T06:36:00.396659+00:00 app[web.1]: at emit (events.js:98:17)
2014-11-20T06:36:00.396658+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
2014-11-20T06:36:00.396661+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/connection.js:512:10)
2014-11-20T06:36:00.394676+00:00 app[web.1]: /app/node_modules/connect-mongo/lib/connect-mongo.js:178
2014-11-20T06:36:00.415816+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/" host=enigmatic-coast-5373.herokuapp.com request_id=165ef7e7-a68a-44b0-9706-f72fcd9a0ba4 fwd="54.83.129.179" dyno=web.1 connect=2ms service=540ms status=503 bytes=0
2014-11-20T06:36:01.075007+00:00 heroku[web.1]: State changed from crashed to starting
2014-11-20T06:36:01.074333+00:00 heroku[web.1]: State changed from up to crashed
2014-11-20T06:36:01.057123+00:00 heroku[web.1]: Process exited with status 8
2014-11-20T06:36:02.976453+00:00 heroku[web.1]: Starting process with command `node app.js`
2014-11-20T06:36:04.328809+00:00 heroku[web.1]: State changed from starting to up

Your error message is showing that you're trying to connect to your local database on localhost (127.0.0.1).
What you should be doing in your code is using your Herkou environment variables, eg:
module.exports = new Db(settings.db, new Server(process.env.MONGOLAB_URL, {}), {safe: true});

You can connect to your remote mongodb specifying it in the code, and this will affect to the local and cloud implementation, or in heroku, you can use environment variables for cloud use. Go to your app-settings-reveal config vars, and add,
first field: MONGOLAB_URI
second field: mongodb://yourmongolabuser:yourmongolabpass#dsnumber.mongolab.com:number/yourapp
MongoLab shows you the uri, you only must change de User and Password.
Another thing can helps your node app not to crash is changing mode to production, again in env variables:
NODE_ENV=production

Related

"Request timeout" on Heroku

I am having a problem deploying my web app on Heroku. I already set the database on MongoDB Atlas. The database is working when I am running "node app.js" locally. After deploying my project on Heroku I got an Application error and when I run "heroku logs --tail" I got the error below ;
2020-03-07T19:53:58.266177+00:00 heroku[web.1]: Idling
2020-03-07T19:53:58.269259+00:00 heroku[web.1]: State changed from up to down
2020-03-07T19:53:59.799552+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-03-07T19:53:59.987938+00:00 heroku[web.1]: Process exited with status 143
2020-03-07T20:02:06.452667+00:00 heroku[web.1]: Unidling
2020-03-07T20:02:06.468513+00:00 heroku[web.1]: State changed from down to starting
2020-03-07T20:02:09.189010+00:00 heroku[web.1]: Starting process with command `node app.js`
2020-03-07T20:02:11.522634+00:00 app[web.1]: Server started on port 3000
2020-03-07T20:02:12.987457+00:00 heroku[web.1]: State changed from starting to up
2020-03-07T20:02:41.597213+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connection <monitor> to 35.172.242.193:27017 closed
2020-03-07T20:02:41.597235+00:00 app[web.1]: at new MongooseServerSelectionError (/app/node_modules/mongoose/lib/error/serverSelection.js:22:11)
2020-03-07T20:02:41.597236+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:808:32)
2020-03-07T20:02:41.597237+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:333:15)
2020-03-07T20:02:41.597237+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:14:10)
2020-03-07T20:02:41.597238+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:955:30)
2020-03-07T20:02:41.597238+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
2020-03-07T20:02:41.597239+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:811:32)
2020-03-07T20:02:41.597239+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:723:14)
2020-03-07T20:02:41.597239+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
2020-03-07T20:02:41.597240+00:00 app[web.1]: at internal/main/run_main_module.js:17:11
2020-03-07T20:02:41.597341+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
2020-03-07T20:02:41.597434+00:00 app[web.1]: (node:4) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
2020-03-07T20:02:43.524590+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=protected-coast-44428.herokuapp.com request_id=9a7b66e6-1280-4d0c-b13d-10548513bc70 fwd="159.146.14.191" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=https
2020-03-07T20:03:17.579588+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/favicon.ico" host=protected-coast-44428.herokuapp.com request_id=3d335054-de74-4abb-982c-135988919edb fwd="159.146.14.191" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https
Please note that I don't have any favicon.ico in my project. I had it in my previous project and I deleted that project on Heroku because of this error, and I don't know why I am still getting favicon on my error.
I made sure that I wrote the right user name and password in app.js and I added my IP in the whitelist as well.
mongoose.connect("mongodb+srv://username:password*#cluster0-h6uqp.mongodb.net/todolistDB",
{ useNewUrlParser: true, useUnifiedTopology: true });
I solved the issue by changing networking access to 'ALLOW ACCESS FROM ANYWHERE' on MongoDB.
Here
Heroku on free plan, closes the dynos after 30 minutes of inactivity. More on this here.
Going by your logs, it looks like the mongo connection was closed after 30 minutes the app was started. Looks like you are affected by this.
The error though seems to be caused by no handling of mongo connection closing in the app.

heroku is giving me Method not allowed [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 10 months ago.
The community reviewed whether to reopen this question 10 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
Okay, so I've been on this problem for hours now with no idea how to solve this, since I'm just a newbie. I was following a UDEMY course titled WEBDEVBOOTCAMP by Colt Steele. On the deployment section, every time I deploy using Heroku, this gives me a "Method not allowed". I've been following Colt's ways from scratch and that's why I wonder how come it's like this.
These are the Heroku logs that I've been receiving:
2017-08-07T21:45:10.990742+00:00 heroku[web.1]: Starting process with command `npm start`
2017-08-07T21:45:14.881336+00:00 app[web.1]:
2017-08-07T21:45:14.881350+00:00 app[web.1]: > v1#1.0.0 start /app
2017-08-07T21:45:14.881352+00:00 app[web.1]:
2017-08-07T21:45:14.881351+00:00 app[web.1]: > node app.js
2017-08-07T21:45:16.594550+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2017-08-07T21:45:16.594555+00:00 app[web.1]: designed for a production
environment, as it will leak
2017-08-07T21:45:16.594556+00:00 app[web.1]: memory, and will not scale past a single process.
2017-08-07T21:45:16.610398+00:00 app[web.1]: (node:17) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mongoosejs.com/docs/connections.html#use-mongo-client
2017-08-07T21:45:16.612243+00:00 app[web.1]: The Yelp Camp Server is up!
2017-08-07T21:45:16.665653+00:00 app[web.1]: Db.prototype.authenticate method will no longer be available in the next major release 3.x as MongoDB 3.6 will only allow auth against users in the admin db and will no longer allow multiple credentials on a socket. Please authenticate using MongoClient.connect with auth credentials.
2017-08-07T21:45:16.914410+00:00 heroku[web.1]: State changed from starting to up
2017-08-07T21:54:00.075655+00:00 app[api]: Starting process with command `ls` by user lao_tabudlong#yahoo.com
2017-08-07T21:54:03.051279+00:00 heroku[run.4055]: Awaiting client
2017-08-07T21:54:03.090885+00:00 heroku[run.4055]: Starting process with command `ls`
2017-08-07T21:54:03.268924+00:00 heroku[run.4055]: State changed from starting to up
2017-08-07T21:54:08.289699+00:00 heroku[run.4055]: Process exited with status 0
2017-08-07T21:54:08.303853+00:00 heroku[run.4055]: State changed from up to complete
2017-08-07T22:16:51.093190+00:00 heroku[web.1]: Idling
2017-08-07T22:16:51.093810+00:00 heroku[web.1]: State changed from up to down
2017-08-07T22:16:52.026960+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2017-08-07T22:16:52.187881+00:00 heroku[web.1]: Process exited with status 143
2017-08-07T22:38:33.000000+00:00 app[api]: Build started by user lao_tabudlong#yahoo.com
2017-08-07T22:38:44.152229+00:00 heroku[web.1]: State changed from down to starting
2017-08-07T22:38:43.802847+00:00 app[api]: Deploy 8174904f by user lao_tabudlong#yahoo.com
2017-08-07T22:38:43.802847+00:00 app[api]: Release v5 created by user lao_tabudlong#yahoo.com
2017-08-07T22:38:33.000000+00:00 app[api]: Build succeeded
2017-08-07T22:38:45.764651+00:00 heroku[web.1]: Starting process with command `npm start`
2017-08-07T22:38:48.251552+00:00 app[web.1]:
2017-08-07T22:38:48.251586+00:00 app[web.1]: > yelpcamp#1.0.0 start /app
2017-08-07T22:38:48.251586+00:00 app[web.1]: > node app.js
2017-08-07T22:38:48.251587+00:00 app[web.1]:
2017-08-07T22:38:49.001981+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2017-08-07T22:38:49.001994+00:00 app[web.1]: designed for a production environment, as it will leak
2017-08-07T22:38:49.001995+00:00 app[web.1]: memory, and will not scale past a single process.
2017-08-07T22:38:49.018239+00:00 app[web.1]: (node:17) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mongoosejs.com/docs/connections.html#use-mongo-client
2017-08-07T22:38:49.020061+00:00 app[web.1]: The Yelp Camp Server is up!
2017-08-07T22:38:49.043200+00:00 app[web.1]: Db.prototype.authenticate method will no longer be available in the next major release 3.x as MongoDB 3.6 will only allow auth against users in the admin db and will no longer allow multiple credentials on a socket. Please authenticate using MongoClient.connect with auth credentials.
2017-08-07T22:38:49.214038+00:00 heroku[web.1]: State changed from starting to up
2017-08-07T23:10:56.925104+00:00 heroku[web.1]: Idling
2017-08-07T23:10:56.925706+00:00 heroku[web.1]: State changed from up to down
2017-08-07T23:10:58.007504+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2017-08-07T23:10:58.359969+00:00 heroku[web.1]: Process exited with status 143
2017-08-08T04:47:35.000000+00:00 app[api]: Build started by user lao_tabudlong#yahoo.com
2017-08-08T04:47:45.285929+00:00 heroku[web.1]: State changed from down to starting
2017-08-08T04:47:35.000000+00:00 app[api]: Build succeeded
2017-08-08T04:47:45.069248+00:00 app[api]: Release v6 created by user lao_tabudlong#yahoo.com
2017-08-08T04:47:45.069248+00:00 app[api]: Deploy f14ef4fc by user lao_tabudlong#yahoo.com
2017-08-08T04:47:46.628278+00:00 heroku[web.1]: Starting process with command `npm start`
2017-08-08T04:47:48.774464+00:00 app[web.1]:
2017-08-08T04:47:48.774484+00:00 app[web.1]: > yelpcamp#1.0.0 start /app
2017-08-08T04:47:48.774485+00:00 app[web.1]: > node app.js
2017-08-08T04:47:48.774486+00:00 app[web.1]:
2017-08-08T04:47:49.444240+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2017-08-08T04:47:49.444256+00:00 app[web.1]: designed for a production environment, as it will leak
2017-08-08T04:47:49.444256+00:00 app[web.1]: memory, and will not scale past a single process.
2017-08-08T04:47:49.454406+00:00 app[web.1]: (node:17) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mongoosejs.com/docs/connections.html#use-mongo-client
2017-08-08T04:47:49.455893+00:00 app[web.1]: The Yelp Camp Server is up!
2017-08-08T04:47:49.472576+00:00 app[web.1]: Db.prototype.authenticate method will no longer be available in the next major release 3.x as MongoDB 3.6 will only allow auth against users in the admin db and will no longer allow multiple credentials on a socket. Please authenticate using MongoClient.connect with auth credentials.
2017-08-08T04:47:49.919585+00:00 heroku[web.1]: State changed from starting to up
2017-08-08T05:21:42.640479+00:00 heroku[web.1]: Idling
2017-08-08T05:21:42.641117+00:00 heroku[web.1]: State changed from up to down
2017-08-08T05:21:43.112034+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2017-08-08T05:21:43.397138+00:00 heroku[web.1]: Process exited with status 143
2017-08-08T05:35:24.000000+00:00 app[api]: Build started by user lao_tabudlong#yahoo.com
2017-08-08T05:35:34.046061+00:00 app[api]: Release v7 created by user lao_tabudlong#yahoo.com
2017-08-08T05:35:34.046061+00:00 app[api]: Deploy 52579a31 by user lao_tabudlong#yahoo.com
2017-08-08T05:35:34.347211+00:00 heroku[web.1]: State changed from down to starting
2017-08-08T05:35:24.000000+00:00 app[api]: Build succeeded
2017-08-08T05:35:36.040512+00:00 heroku[web.1]: Starting process with command `npm start`
2017-08-08T05:35:38.881422+00:00 app[web.1]:
2017-08-08T05:35:38.881446+00:00 app[web.1]: > yelpcamp#1.0.0 start /app
2017-08-08T05:35:38.881447+00:00 app[web.1]: > node app.js
2017-08-08T05:35:38.881448+00:00 app[web.1]:
2017-08-08T05:35:39.981312+00:00 heroku[web.1]: State changed from starting to up
2017-08-08T05:35:39.914694+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2017-08-08T05:35:39.914717+00:00 app[web.1]: designed for a production environment, as it will leak
2017-08-08T05:35:39.914718+00:00 app[web.1]: memory, and will not scale past a single process.
2017-08-08T05:35:39.932988+00:00 app[web.1]: (node:17) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mongoosejs.com/docs/connections.html#use-mongo-client
2017-08-08T05:35:39.935319+00:00 app[web.1]: The Yelp Camp Server is up!
2017-08-08T05:35:39.967512+00:00 app[web.1]: Db.prototype.authenticate method will no longer be available in the next major release 3.x as MongoDB 3.6 will only allow auth against users in the admin db and will no longer allow multiple credentials on a socket. Please authenticate using MongoClient.connect with auth credentials.
2017-08-08T05:49:20.000000+00:00 app[api]: Build started by user lao_tabudlong#yahoo.com
2017-08-08T05:49:31.423119+00:00 heroku[web.1]: Restarting
2017-08-08T05:49:31.425641+00:00 heroku[web.1]: State changed from up to starting
2017-08-08T05:49:31.128129+00:00 app[api]: Deploy 98890a0e by user lao_tabudlong#yahoo.com
2017-08-08T05:49:31.128129+00:00 app[api]: Release v8 created by user lao_tabudlong#yahoo.com
2017-08-08T05:49:32.024642+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2017-08-08T05:49:32.234319+00:00 heroku[web.1]: Process exited with status 143
2017-08-08T05:49:20.000000+00:00 app[api]: Build succeeded
2017-08-08T05:49:33.865572+00:00 heroku[web.1]: Starting process with command `npm start`
2017-08-08T05:49:36.912525+00:00 app[web.1]:
2017-08-08T05:49:36.912549+00:00 app[web.1]: > yelpcamp#1.0.0 start /app
2017-08-08T05:49:36.912550+00:00 app[web.1]: > node app.js
2017-08-08T05:49:36.912550+00:00 app[web.1]: `enter code here`
2017-08-08T05:49:38.250325+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2017-08-08T05:49:38.250352+00:00 app[web.1]: designed for a production environment, as it will leak
2017-08-08T05:49:38.250353+00:00 app[web.1]: memory, and will not scale past a single process.
2017-08-08T05:49:38.270747+00:00 app[web.1]: (node:17) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mongoosejs.com/docs/connections.html#use-mongo-client
2017-08-08T05:49:38.273329+00:00 app[web.1]: The Yelp Camp Server is up!
2017-08-08T05:49:38.314596+00:00 app[web.1]: Db.prototype.authenticate method will no longer be available in the next major release 3.x as MongoDB 3.6 will only allow auth against users in the admin db and will no longer allow multiple credentials on a socket. Please authenticate using MongoClient.connect with auth credentials.
2017-08-08T05:49:38.342241+00:00 heroku[web.1]: State changed from starting to up
From the Q&A on the webdevbootcamp video:
"Make sure you are trying to access the correct link that gets printed to the console. You shouldn't try to load the link which ends with .git since that is just the repository location.
Your link should look like https://your-app-name.herokuapp.com/"
I faced the same problem. Check your url, you might be opening the one which ends in .git. Instead go to your heroku dashboard and open the app from there using the correct url.
This Problem Bacicaly comes when you are using wrong link
Your link should be like https://test-name.herokuapp.com/
With reference to Matt's answer: -
Even if the deployment is successful, but you have not defined a html as to how the webpage should look like, then you get 'Method not allowed', meaning,
"https://your-app-name.herokuapp.com/" will have "Method not allowed".
But there is a way you can test if the deployment is done okay and you are getting Response 200.
Open jupyter notebook and run:
Reference: https://towardsdatascience.com/create-an-api-to-deploy-machine-learning-models-using-flask-and-heroku-67a011800c50
In short :
import requests
import json
# local url
url = 'https://your-app.herokuapp.com/'
# sample data
data = {'Pclass': 3
, 'Age': 2
, 'SibSp': 1
, 'Fare': 50}
data = json.dumps(data)
send_request = requests.post(url, data) #should get : Response 200
print(send_request.json())# should get predicted result
I faced the same issue while deploying a golang web app on heroku. The root cause of the issue was with how i frame the url. The url generated by heroku consisted of a trailing "/" and i was constructing the url as "heroku_url" + "/login" which resulted in heroku_url//login, try removing a / from heroku_url or from your route and give a try.
Before deploying your app make sure your project is on the main branch.
Refer: Git Branches.

MongoDB not connecting to Heroku? Application Error

I tested it out using npm modules: "node-dev" on the backend.js and "serve" on the root directory of the folder.
I have these 2 guides that tried to help me:
http://www.tilcode.com/deploying-a-mean-stack-app-to-heroku/
and another one from scotch.io "Use MongoDB with a Node.js Application on Heroku"
What I didn't do from the articles that shouldn't matter: in tilcode, it said use to github to generate an SSH key...instead I made one using my mac and a terminal command using some guide.
To summarize my steps:
Login to heroku, create the app
use git commands to add, commit all the files in my github into heroku and pushed them into heroku
I even put the mlab addon and filled out the URI.
It deployed "successfully" but when visiting the app, it says "application failed"
My suspicions:
I do have another working app that uses postgreSQL...but I put it on 'maintenance mode' since my free account only allows for one active dynamo.
Instead of uploading all my node modules, I learned I could have heroku install it like this:
heroku config:set NPM_CONFIG_PRODUCTION=false
I think it may be how I referenced the backend from my frontend javascript.
// var API = 'http://localhost:5000';
var API = 'http://limitless-falls-21423.herokuapp.com';
var app = angular.module('HAL-app', ['ngRoute', 'ngCookies']);
// Some other stuff that came from sandbox app.js
app.directive('whenScrolled', function() {
return function(scope, elm, attr) {
var raw = elm[0];
elm.bind('scroll', function() {
if (raw.scrollTop + raw.offsetHeight >= raw.scrollHeight) {
scope.$apply(attr.whenScrolled);
}
});
};
});
Lastly, when I ran heroku logs --tail I got these messages:
2016-09-05T01:35:27.417956+00:00 app[web.1]: npm ERR! Linux 3.13.0-93-generic
2016-09-05T01:35:27.418339+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-09-05T01:35:27.418593+00:00 app[web.1]: npm ERR! node v5.11.1
2016-09-05T01:35:27.418931+00:00 app[web.1]: npm ERR! npm v3.8.6
2016-09-05T01:35:27.419219+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2016-09-05T01:35:27.419386+00:00 app[web.1]: npm ERR! hallocam#1.0.0 start:
node backend.js
2016-09-05T01:35:37.178679+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=limitless-falls-21423.herokuapp.com request_id=4bc9639f-3f64-4c0b-9b0d-d99b967f1b36 fwd="73.54.129.252" dyno= connect= service= status=503 bytes=
******EDIT after Yashua's comment**
I now get a "cannot get" message when visiting the app. Was kinda hesitant about limiting my heroku variables to just the:
NODE_ENV=production
But I guess it makes since since if I keep my mongodb (mongo labs) credentials uploaded and hidden using .gitignore.
Anyway, I'm still thinking it's not "getting" my routes which I have setup my angularjs file like this:
// var API = 'http://localhost:5000'; ##this is the old way to connect my front end factory routes to the backend hosted on 5000
I have it like this right now
var API = 'http://obscure-brook-35938.herokuapp.com/';
I think it may have to look like this:
var API = process.env.PORT
The purpose of the API is to be used for my angular factories like this:
app.factory('backEnd', function($http) {
return {
getSignUp: function(data) {
return $http({
method: 'POST',
url: API + '/signup',
data: data
});
},
getLogin: function(data) {
return $http({
method: 'POST',
url: API + '/login',
data: data
});
},
New Heroku logs --tail
2016-09-05T15:42:52.796464+00:00 heroku[router]: at=info method=GET path="/" host=obscure-brook-35938.herokuapp.com request_id=41fa32e2-42cc-426d-a0d0-ef6755329497 fwd="73.54.129.252" dyno=web.1 connect=1ms service=18ms status=404 bytes=243
2016-09-05T15:42:53.893156+00:00 heroku[router]: at=info method=GET path="/" host=obscure-brook-35938.herokuapp.com request_id=dec235fd-6d54-42e6-b0cc-2f83920d500d fwd="73.54.129.252" dyno=web.1 connect=1ms service=8ms status=404 bytes=243
2016-09-05T15:42:54.602312+00:00 heroku[router]: at=info method=GET path="/" host=obscure-brook-35938.herokuapp.com request_id=8ceb054b-78e9-49b8-bdee-286ca6efcb0d fwd="73.54.129.252" dyno=web.1 connect=1ms service=3ms status=404 bytes=243
Hard to tell offhand but here are some pointers:
I looked at your repo and your package.json is invalid in 2 places. Use a JSON validator.
Secondly your frontend app will not be an issue. You should be able to go to the server URL directly and not have it crashed.
Change your database password if you haven't already. I see that you deleted your mongo_creds.json file but the history is available on GitHub.
The only vars you should need on Heroku is NODE_CONFIG set to production.
I'm closing this thread because it's getting pretty lengthy and a separate problem has arose. As #yashua said, the best way to solve this mongodb/heroku problems is to take it one step at a time. Some tools I've learned from this experience:
If using NPMs to test, that's great as it builds confidence. But to truly test heroku, use its 'heroku local' or 'heroku local web' to test it out locally first (serve it up), then it'll help narrow down further issues when deploying/'git push heroku master'
Build a solid understanding of how .env files work (really, they're
just configuration files to store credential information). I've been
using .json files to store mine, then use .gitignore to stop them
from appearing publicly. Heroku has its own secret keepers in the
form of Procfile and .env
I'm up to a point now where I consolidated my backend/frontend into one root directory. But my frontend and backend use 2 different ports to work when it should only use one. Not sure the best way to approach that since when I do [supposedly] feed them all the same port as 'process.env.MONGOLAB_URI' I get an error that hints that I have it wrong.
2016-09-05T23:36:51.802697+00:00 app[web.1]: /app/node_modules/mongodb/lib/server.js:261
2016-09-05T23:36:51.802698+00:00 app[web.1]: process.nextTick(function() { throw err; })
2016-09-05T23:36:51.802698+00:00 app[web.1]: ^
2016-09-05T23:36:51.803862+00:00 app[web.1]: MongoError: failed to connect to server [#:27017] on first connect
2016-09-05T23:36:51.803864+00:00 app[web.1]: at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:313:35)
2016-09-05T23:36:51.803864+00:00 app[web.1]: at emitOne (events.js:96:13)
2016-09-05T23:36:51.803865+00:00 app[web.1]: at Pool.emit (events.js:188:7)
2016-09-05T23:36:51.803865+00:00 app[web.1]: at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:260:12)
2016-09-05T23:36:51.803866+00:00 app[web.1]: at Connection.g (events.js:286:16)
2016-09-05T23:36:51.803867+00:00 app[web.1]: at emitTwo (events.js:106:13)
2016-09-05T23:36:51.803867+00:00 app[web.1]: at Connection.emit (events.js:191:7)
2016-09-05T23:36:51.803868+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:162:49)
2016-09-05T23:36:51.803868+00:00 app[web.1]: at Socket.g (events.js:286:16)
2016-09-05T23:36:51.803869+00:00 app[web.1]: at emitOne (events.js:96:13)
2016-09-05T23:36:51.803870+00:00 app[web.1]: at Socket.emit (events.js:188:7)
2016-09-05T23:36:51.803870+00:00 app[web.1]: at connectErrorNT (net.js:1016:8)
2016-09-05T23:36:51.803871+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:74:11)
2016-09-05T23:36:51.803871+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:98:9)
2016-09-05T23:36:51.881752+00:00 heroku[web.1]: State changed from starting to crashed
2016-09-05T23:36:51.867426+00:00 heroku[web.1]: Process exited with status 1

Heroku deployment error

I've successfully pushed my app to heroku, but when I heroku open I get an Application error on my page.
Checking the logs I can see
2016-02-06T17:06:42.092148+00:00 heroku[slug-compiler]: Slug compilation started
2016-02-06T17:06:42.092157+00:00 heroku[slug-compiler]: Slug compilation failed:
failed to compile Node.js app
2016-02-06T17:07:00.738280+00:00 heroku[router]: at=info code=H81 desc="Blank ap
p" method=GET path="/" host=pacific-headland-94684.herokuapp.com request_id=9bcd
ba26-7eef-4323-baff-86e4f6cc7c11 fwd="109.175.110.196" dyno= connect= service= s
tatus=502 bytes=
And later on in the logs I also get
2016-02-09T16:20:30.835195+00:00 heroku[slug-compiler]: Slug compilation finished
2016-02-09T16:20:32.198289+00:00 heroku[web.1]: Starting process with command `n
ode server.js`
2016-02-09T16:20:34.904089+00:00 app[web.1]: throw err;
2016-02-09T16:20:34.904090+00:00 app[web.1]: ^
2016-02-09T16:20:34.904079+00:00 app[web.1]: module.js:338
2016-02-09T16:20:34.904092+00:00 app[web.1]: at Function.Module._load (modul
e.js:278:25)
2016-02-09T16:20:34.904091+00:00 app[web.1]: Error: Cannot find module '/app/ser
ver.js'
2016-02-09T16:20:34.904092+00:00 app[web.1]: at Function.Module._resolveFile
name (module.js:336:15)
2016-02-09T16:20:34.904093+00:00 app[web.1]: at Function.Module.runMain (mod
ule.js:501:10)
2016-02-09T16:20:34.904094+00:00 app[web.1]: at startup (node.js:129:16)
2016-02-09T16:20:34.904094+00:00 app[web.1]: at node.js:814:3
2016-02-09T16:20:35.976063+00:00 heroku[web.1]: Process exited with status 1
2016-02-09T16:20:35.977672+00:00 heroku[web.1]: State changed from starting to c
rashed
If anyone is interested for full logs, here's a link: https://www.dropbox.com/s/8l261wmg99yahzc/heroku_logs.txt?dl=0
All the similar problems I googled usually happen when pushing the app to heroku, but as I've said my push was successful.
The problem was that git repo was not in the apps folder(named node in my case) but in a folder up one level (named app, this folder didn't exist on local), so when I pushed it on heroku, procfile searched for server.js in folder named app instead of the root and couldn't find anything.
After checking the pathing on GitDesktop I saw the folder structure and reinitialized the repository in a right place, pushed the changes and fixed the problem.

Node.js + socket.io runs locally with foreman but crashes on heroku

I get the following error when running on heroku:
4-07-26T22:24:01.691178+00:00 heroku[web.1]: State changed from starting to crashed
2014-07-26T22:24:01.692242+00:00 heroku[web.1]: State changed from crashed to starting
2014-07-26T22:24:04.483585+00:00 app[web.1]:
26)
...
2014-07-26T22:24:04.484066+00:00 app[web.1]: ^
2014-07-26T22:24:04.485813+00:00 app[web.1]: at Module.load (module.js:356:32)
2014-07-26T22:24:04.484057+00:00 app[web.1]: throw err;
2014-07-26T22:24:04.485806+00:00 app[web.1]: at require (module.js:380:17)
2014-07-26T22:24:04.483677+00:00 app[web.1]: module.js:340
2014-07-26T22:24:04.485808+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/socket.io/node_modules/socket.io-parser/node_modules/emitter/index.js:6:13)
If I use, "heroku labs:enable websockets", I get "No such feature: websockets"
Problem
Heroku can't find an object in your ../emitter/index.js. Some folders of the socket.io modules are "gitignored". (Why?)
It looks like websockets are no heroku:labs feature anymore and are enabled by default. I ran the socket.io chat example without enabling the labs feature.
Quick Solution
git add -A --force | then commit and deploy

Resources