Heroku deployment error - node.js

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.

Related

Host Provider Heroku doesn't seem to pick up concurrently command in "npm run start"

Stack Overflow Question
Host Provider Heroku doesn't seem to pick up concurrently command in "npm run start". I can get this start command to work with "heroku local web" but get the below log errors when running the same thing on heroku host.
I noticed that for some other node full stack projects, the backend is setup to run on startup. In these cases there is routing setup in express so that the request either routes to a backend route or is passed off to a static front endpape. My issues is that I don't have express to support this. I'm just running json-server on the backend (or trying) and my vue.js content on the front.
Is there a work around to get Heroku configured to start both the a front and backend server?
I can run the "npm run start" locally but not on Heroku:
It seems like Heroku (at least by default) is configured to start a node app by running "npm run start". As a result, I have the following entry in my package.json:
package.json
"start": "concurrently \"export NODE_ENV=production\" \"json-server --watch db.json\" \"vue-cli-service serve --mode production\""
Heroku Logs:
2021-10-17T18:30:52.000000+00:00 app[api]: Build succeeded
2021-10-17T18:30:54.001782+00:00 heroku[web.1]: Starting process with command `npm start`
2021-10-17T18:30:55.002829+00:00 app[web.1]:
2021-10-17T18:30:55.002845+00:00 app[web.1]: > my-vue-app#0.1.0 start /app
2021-10-17T18:30:55.002845+00:00 app[web.1]: > concurrently "export NODE_ENV=production" "json-server --watch db.json" "vue-cli-service serve --mode production"
2021-10-17T18:30:55.002846+00:00 app[web.1]:
2021-10-17T18:30:55.226381+00:00 app[web.1]: [1] /bin/sh: 1: json-server: not found
2021-10-17T18:30:55.227075+00:00 app[web.1]: [2] /bin/sh: 1: vue-cli-service: not found
2021-10-17T18:30:55.228104+00:00 app[web.1]: [2] vue-cli-service serve --mode production exited with code 1272021-10-17T18:30:55.228540+00:00 app[web.1]: [1] json-server --watch db.json exited with code 127
2021-10-17T18:30:55.228781+00:00 app[web.1]: [0] export NODE_ENV=production exited with code 0
2021-10-17T18:30:55.238234+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-10-17T18:30:55.238413+00:00 app[web.1]: npm ERR! errno 1
2021-10-17T18:30:55.242355+00:00 app[web.1]: npm ERR! my-vue-app#0.1.0 start: `concurrently "export NODE_ENV=production" "json-server --watch db.json" "vue-cli-service serve --mode production"`
2021-10-17T18:30:55.242419+00:00 app[web.1]: npm ERR! Exit status 1
2021-10-17T18:30:55.242477+00:00 app[web.1]: npm ERR!
2021-10-17T18:30:55.242529+00:00 app[web.1]: npm ERR! Failed at the my-vue-app#0.1.0 start script.
2021-10-17T18:30:55.242567+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-10-17T18:30:55.248113+00:00 app[web.1]:
2021-10-17T18:30:55.248206+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-10-17T18:30:55.248255+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-10-17T18_30_55_242Z-debug.log
2021-10-17T18:30:55.386385+00:00 heroku[web.1]: Process exited with status 1
2021-10-17T18:30:55.642820+00:00 heroku[web.1]: State changed from starting to crashed
2021-10-17T18:30:59.838564+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=myvueapp1.herokuapp.com request_id=eaa81f4f-8d66-4dcc-92e6-5ac730cf9c9c fwd="73.181.221.158" dyno= connect= service= status=503 bytes= protocol=https
2021-10-17T18:31:00.272840+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=myvueapp1.herokuapp.com request_id=a3108da6-5ba3-48cf-8bc4-4b5784a6d171 fwd="73.181.221.158" dyno= connect= service= status=503 bytes= protocol=https
2021-10-17T18:32:51.000000+00:00 app[api]: Build started by user mark.johnson.
2021-10-17T18:33:54.181436+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=myvueapp1.herokuapp.com request_id=91cd8f28-f155-4b58-b4ac-bb1539e06413 fwd="73.181.221.158" dyno= connect= service= status=503 bytes= protocol=https
2021-10-17T18:33:54.362762+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=myvueapp1.herokuapp.com request_id=8103d63b-9a7d-46f9-b2c1-5d662e77b539 fwd="73.181.221.158" dyno= connect= service= status=503 bytes= protocol=https
2021-10-17T18:34:35.091986+00:00 heroku[web.1]: State changed from crashed to starting
2021-10-17T18:34:34.685663+00:00 app[api]: Deploy 6abb4c8b by user mark.johnson.
2021-10-17T18:34:34.685663+00:00 app[api]: Release v4 created by user mark.johnson.
2021-10-17T18:34:38.788809+00:00 heroku[web.1]: Starting process with command `npm start`
2021-10-17T18:34:41.024848+00:00 app[web.1]:
2021-10-17T18:34:41.024866+00:00 app[web.1]: > my-vue-app#0.1.0 start /app
2021-10-17T18:34:41.024866+00:00 app[web.1]: > concurrently "export NODE_ENV=production" "json-server --watch db.json" "vue-cli-service serve --mode production"
2021-10-17T18:34:41.024867+00:00 app[web.1]:
2021-10-17T18:34:41.548998+00:00 app[web.1]: [1] Done
2021-10-17T18:34:41.555274+00:00 app[web.1]: [1]
2021-10-17T18:34:41.555534+00:00 app[web.1]: [1] Resources
2021-10-17T18:34:41.555535+00:00 app[web.1]: [1] http://localhost:3000/table1
2021-10-17T18:34:41.555535+00:00 app[web.1]: [1] http://localhost:3000/table2
2021-10-17T18:34:41.555535+00:00 app[web.1]: [1]
2021-10-17T18:34:41.555536+00:00 app[web.1]: [1] Home
2021-10-17T18:34:41.555536+00:00 app[web.1]: [1] http://localhost:3000
2021-10-17T18:34:41.555536+00:00 app[web.1]: [1]
2021-10-17T18:34:41.555781+00:00 app[web.1]: [1] Type s + enter at any time to create a snapshot of the database
As I said here and here, the common approach in an enterprise architecture is to have one app by repository and server.
Imagine that your microservice (json) process needs to have more ram because handle heavy operations and since your web is an spa, does not need anything because it is just static files after npm run build. In this case, depending of the infrastructure, you could scale vertically/horizontally every artifact (api and web) easily. If you have several process in the same server, you would be backing up a little to the monolithic architecture. This is just one of the several advantages like:
https://michaelwashburnjr.com/blog/4-reasons-web-app-separated-frontend-backend
https://softwareengineering.stackexchange.com/a/299550/204271
Api and Web
In heroku and any platform, applications has its own port. Also you will have noticed that in your developer laptop:
vue app runs at : http://localhost:8080
api mock at http://localhost:3000/posts/1
As you can see , you have two apps here, each one with its own port. In the future, each one will have its own domain : acme.com and acme-api.com
Just for test
The usage of json-server to publish a single file (db.json) as a microservice or rest api is just for testing or poc purposes. It would be crazy to use concurrently in a real application for real users.
I used this on early development stage, when the api/microservice does not exist yet.
When api is ready to use and has its own http domain (http://acme-api.com) served on its own server, I set this new url on my web.
Two apps (api + web)
If you don't want to complicate and be prepared for a real enterprise deployment, you should create two different app on your heroku account
acme-web with your vue code. This usually needs to have the npm run dev, npm run build and npm run start. Your start script should be something like this: "start": "vue-cli-service serve --mode production"
acme-api with your real api/microservice source code(database connection and other features). Also in early stage (api does not exist yet) you could put here your db.json and you start script should look like this: "start": "json-server --watch db.json"
One app
Anyway, if you want or need to have all (web+api) in one server or container, you should use another provider like aws, gcp, azure, etc. On that provider your concurrently command will work.
On heroku, you can't run two diferent web process on the same dyno.
Workaround
As some framework does like MEAN, MERN & MEVN and other modern monolithics, you could use an express server to serve your api and your web.
This app should look like this:
var express = require('express');
var jsonServer = require('json-server');
var app = express();
//publish the static result of npm run build (vue)
//https://github.com/jrichardsz/nodejs-express-snippets/tree/master/simple-static-server
app.use('/',
express.static(path.join(__dirname, "site" || proces.env.SITE_FOLDER)),
);
//run json-server programmatically here
//https://github.com/typicode/json-server/issues/253#issuecomment-205509836
app.use('/api', jsonServer.router('db.json'));
app.listen(3000);
Variables by environment
If you opt for and advanced distributed architecturem and yo have at least two environments: testing and production and you don't want to change the variables from time to time when you switch your application from your laptop to next environments dev > testing > production you will need to properly handle your environment variables using the heroku manager.

How do I run this node express app on Heroku?

I already have one app running on Heroku just fine which I created a few weeks ago for the first time.
Here is the git repo for the functioning app - https://github.com/Sean-99-04/basic
However when I try to run my newest app, it does not work. It builds fine, but gives an application error when ran.
Here is the git repo for that - https://github.com/Sean-99-04/History-Blog
Also I am runnnig this through GitHub, not through Heroku CLI.
I have been searching online for the last 3 hours for answers and here are some things mentioned which I made sure to unclude:
Procfile with code "web:node ./server.js"
package.json with code "script": {"start": "node server.js"}
In server.js I have process.env.PORT and all other necessary process.env's
I greatly appreciate any help and thank you in advance.
This is the error in logs:
2021-01-11T16:50:16.910561+00:00 app[web.1]: npm ERR! Failed at the history-blog#1.0.0 start script.
2021-01-11T16:50:16.910689+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-01-11T16:50:16.915638+00:00 app[web.1]:
2021-01-11T16:50:16.915831+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-01-11T16:50:16.915958+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-01-11T16_50_16_911Z-debug.log
2021-01-11T16:50:16.988688+00:00 heroku[web.1]: Process exited with status 1
2021-01-11T16:50:17.025320+00:00 heroku[web.1]: State changed from starting to crashed
2021-01-11T16:50:17.966848+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=history-blog.herokuapp.com request_id=f274158b-5399-49ab-97d9-5a83bb387a13 fwd="95.147.237.100" dyno= connect= service= status=503 bytes= protocol=https
As mentioned in the comments, the failure was caused by trying to loading dotenv. The reason that happened despite Heroku's default NODE_ENV being production is that you're assigning in the check, which returns the string development, which is truthy — so it gets loaded.
What you have: if ((process.env.NODE_ENV = "development")) {
What you want: if (process.env.NODE_ENV === "development") {

"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.

Password authentication failing for ghost blog on heroku server

I'm trying to setup Ghost(node.js blogging app) to run on a heroku server. I've followed this tutorial here but I'm getting an Application error when I load the app URL. Looking at the logs, I'm getting the following stack trace:
2016-12-16T10:00:08.185701+00:00 heroku[web.1]: Starting process with command `NODE_ENV=production node index.js`
2016-12-16T10:00:11.989635+00:00 app[web.1]:
2016-12-16T10:00:11.989655+00:00 app[web.1]: ERROR: password authentication failed for user "xxxxxxxxxxxxxx"
2016-12-16T10:00:11.989656+00:00 app[web.1]: error: password authentication failed for user "xxxxxxxxxxxxxx"
2016-12-16T10:00:11.989656+00:00 app[web.1]:
2016-12-16T10:00:11.989658+00:00 app[web.1]: at Connection.parseMessage (/app/node_modules/pg/lib/connection.js:361:17)
2016-12-16T10:00:11.989657+00:00 app[web.1]: at Connection.parseE (/app/node_modules/pg/lib/connection.js:534:11)
2016-12-16T10:00:11.989659+00:00 app[web.1]: at TLSSocket.<anonymous> (/app/node_modules/pg/lib/connection.js:105:22)
2016-12-16T10:00:11.989660+00:00 app[web.1]: at emitOne (events.js:96:13)
2016-12-16T10:00:11.989661+00:00 app[web.1]: at readableAddChunk (_stream_readable.js:176:18)
2016-12-16T10:00:11.989662+00:00 app[web.1]: at TLSSocket.Readable.push (_stream_readable.js:134:10)
2016-12-16T10:00:11.989660+00:00 app[web.1]: at TLSSocket.emit (events.js:188:7)
2016-12-16T10:00:11.989663+00:00 app[web.1]: at TLSWrap.onread (net.js:548:20)
2016-12-16T10:00:11.989664+00:00 app[web.1]:
2016-12-16T10:00:12.059675+00:00 heroku[web.1]: Process exited with status 0
2016-12-16T10:00:12.098899+00:00 heroku[web.1]: State changed from starting to crashed
2016-12-16T10:00:11.574238+00:00 app[web.1]: WARNING: Ghost is attempting to use a direct method to send email.
2016-12-16T10:00:11.574254+00:00 app[web.1]: It is recommended that you explicitly configure an email service.
2016-12-16T10:00:11.575112+00:00 app[web.1]: Help and documentation can be found at http://support.ghost.org/mail.
2016-12-16T10:00:11.575114+00:00 app[web.1]:
2016-12-16T12:20:59.497399+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ai-blog.herokuapp.com request_id=a725a350-ade1-4f00-9b8a-125fac34eb23 fwd="82.46.0.56" dyno= connect= service= status=503 bytes=
2016-12-16T12:21:01.504908+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ai-blog.herokuapp.com request_id=cc0c4f9b-f3af-4867-942f-0c7f295f9b90 fwd="82.46.0.56" dyno= connect= service= status=503 bytes=
2016-12-16T12:21:03.381794+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ai-blog.herokuapp.com request_id=ee190254-0159-4ba0-aa74-6e58f661c966 fwd="82.46.0.56" dyno= connect= service= status=503 bytes=
It seems that the important part of the error here is that the password is failing: But I've double and tripled check the all of the heroku varibles are set correctly, i.e. no typos, no extra spaces added at the start end of the string.
Additionally, the app runs fine locally.
The issue seems relatively common, but I've tried most of the solutions from other posts and nothing seems to be resolving the issue.
Solutions that I've tried:
Checked all varibles for typos
Checked the correct database is promoted
Manually adding the user credendials to the remote database(For some reason I can still access the remote database through the command line)
Ran the following command heroku config:set PGSSLMODE=require
ensured that I'm using https in the url when connecting to the site through a browser
I've added the following to the db params in the production environment of my config.js ssl: true
I've also checked that I'm in production environment
Sugguestions that I haven't tried:
Someone suggested that node needs to be updated. But I can't see any way of updating whatever version of node it is that heroku uses.
Somone suggested that postgres needs to be updated. But I can't see any way of updating that on heroku servers either. However, I did update the version number in the package.json file from 4.1.1 to 4.5.5 and moved it from optionalDependencies to dependencies.
editing the pg_hba.conf - again, I imagine this file exists on heroku servers and I can't access it
Anyone got any ideas?
I encounter the same problem while trying to upgrade to Ghost version 0.11.3 and deploying to Heroku.
I was able to solve the problem by upgrading the PostgreSQL npm package.
In package.json:
{
"dependencies": {
"pg": "^4.5.5",
},
"optionalDependencies": {
"pg": "^4.5.5"
}
}
And you will also need to modify the npm-shrinkwrap.json file:
{
"dependencies": {
"pg": {
"version": "^4.5.5",
"from": "pg#4.5.5",
"resolved": "https://registry.npmjs.org/pg/-/pg-4.5.5.tgz",
"dependencies": {...}
}
}
}
After that, check that the PG npm package version was updated correctly by taking a look at Heroku's deploy log. It should say something like:
remote: -----> Build succeeded!
remote: ├── ...
remote: ├── pg#4.5.5
remote: ├── ...

Use Heroku addon mongolab with 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

Resources