How to deploy Node app to heroku?

HI guys, I’m trying to deploy my node app to Heroku but I keep seeing “Error!”
when I look at my site. How can I figure out the problem? I’m new to Heroku so I would appreciate any help. Maybe I didn’t prep my app well enough before deploying?

LINK: https://pet-store-inventory.herokuapp.com/
Repo: GitHub - pllealfunes/pet-store

1 Like

I don’t have time to delve deeply but I remember having difficulty with my first apps in heroku. First, I had to figure out how to set up my environment variables in their interface and then I had to figure out how to get the logs from the CL interface.

I would suggest looking at those.

1 Like

When I run “heroku local web” I can see my project…So after some reading I added a Procfile in my root directory and then I did heroku logs --tail in the terminal.

I saw this in my logs

UnhandledPromiseRejectionWarning: MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/

I looked at MongoDB Atlas and I do see my ip address under Security → Network Access

1 Like

Does the request to your Atlas cluster come from your computer, or from the server that hosts your Heroku App? I would assume the latter, so I’d next try to whitelist 0.0.0.0 (everyone) and see if that fixes it.

1 Like

So I added 0.0.0.0 and I still get the error. I also see this in my terminal:

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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict`

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.

Also

GET /favicon.ico 404 182.542
1 Like

I tried out this article DEPLOYING YOUR NODE/EXPRESS APP ON HEROKU | by Amadi Austin Chukwuemeka | Studevs | Medium and it didn’t work.

My procfile is set to

web: node ./bin/ww

Right now the below are what I see when I do heroku logs --tail

current: https://github.com/pllealfunes/pet-store

2021-09-04T02:46:19.385771+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1072:14)
2021-09-04T02:46:19.385772+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
2021-09-04T02:46:19.385772+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:937:32)
2021-09-04T02:46:19.385772+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:778:12)
2021-09-04T02:46:19.385772+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:961:19)
2021-09-04T02:46:19.385773+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:92:18)
2021-09-04T02:46:19.385773+00:00 app[web.1]: at Object.<anonymous> (/app/bin/www:7:11)
2021-09-04T02:46:19.385773+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1072:14)
2021-09-04T02:46:19.385773+00:00 app[web.1]: (Use `node --trace-warnings ...` to show where the warning was created)
2021-09-04T02:46:19.385791+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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
2021-09-04T02:46:19.385835+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.
2021-09-04T02:46:33.458594+00:00 heroku[router]: at=info method=GET path="/" host=pet-store-inventory.herokuapp.com request_id=1b4a11c6-9876-4cc5-89b4-21b5430d6081 fwd="73.249.83.68" dyno=web.1 connect=0ms service=10004ms status=200 bytes=123 protocol=https
2021-09-04T02:46:33.459808+00:00 app[web.1]: GET / 200 10002.132 ms - -

2021-09-04T02:50:47.000000+00:00 app[api]: Build succeeded
2021-09-04T02:50:47.005750+00:00 heroku[web.1]: Restarting
2021-09-04T02:50:47.007715+00:00 heroku[web.1]: State changed from up to starting
2021-09-04T02:50:47.817771+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2021-09-04T02:50:47.992248+00:00 heroku[web.1]: Process exited with status 143
2021-09-04T02:50:49.621385+00:00 heroku[web.1]: Starting process with command `node ./bin/www`
2021-09-04T02:50:52.332929+00:00 heroku[web.1]: State changed from starting to up
2021-09-04T02:51:03.367398+00:00 heroku[router]: at=info method=GET path="/" host=pet-store-inventory.herokuapp.com request_id=f39f6b6e-dee9-44a5-bb09-27c6f6b34d08 fwd="73.249.83.68" dyno=web.1 connect=0ms service=10010ms status=200 bytes=123 protocol=https
2021-09-04T02:51:03.368504+00:00 app[web.1]: GET / 200 10006.273 ms - -
2021-09-04T02:51:22.193767+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
2021-09-04T02:51:22.193774+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:846:32)
2021-09-04T02:51:22.193775+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:351:10
2021-09-04T02:51:22.193777+00:00 app[web.1]: at /app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
2021-09-04T02:51:22.193777+00:00 app[web.1]: at new Promise (<anonymous>)
2021-09-04T02:51:22.193778+00:00 app[web.1]: at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
2021-09-04T02:51:22.193778+00:00 app[web.1]: at Mongoose._promiseOrCallback (/app/node_modules/mongoose/lib/index.js:1149:10)
2021-09-04T02:51:22.193779+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:350:20)
2021-09-04T02:51:22.193779+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:18:10)
2021-09-04T02:51:22.193780+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1072:14)
2021-09-04T02:51:22.193780+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
2021-09-04T02:51:22.193780+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:937:32)
2021-09-04T02:51:22.193781+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:778:12)
2021-09-04T02:51:22.193781+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:961:19)
2021-09-04T02:51:22.193781+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:92:18)
2021-09-04T02:51:22.193782+00:00 app[web.1]: at Object.<anonymous> (/app/bin/www:7:11)
2021-09-04T02:51:22.193782+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1072:14)
2021-09-04T02:51:22.193783+00:00 app[web.1]: (Use `node --trace-warnings ...` to show where the warning was created)
2021-09-04T02:51:22.193815+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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
2021-09-04T02:51:22.193852+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.
2021-09-04T03:05:07.000000+00:00 app[api]: Build succeeded
2021-09-04T03:05:07.376618+00:00 heroku[web.1]: Restarting
2021-09-04T03:05:07.381416+00:00 heroku[web.1]: State changed from up to starting
2021-09-04T03:05:08.197027+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2021-09-04T03:05:08.427975+00:00 heroku[web.1]: Process exited with status 143
2021-09-04T03:05:10.533805+00:00 heroku[web.1]: Starting process with command `node ./bin/www`
2021-09-04T03:05:12.802747+00:00 heroku[web.1]: State changed from starting to up
2021-09-04T03:05:42.586012+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
2021-09-04T03:05:42.586042+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:846:32)
2021-09-04T03:05:42.586046+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:351:10
2021-09-04T03:05:42.586049+00:00 app[web.1]: at /app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
2021-09-04T03:05:42.586052+00:00 app[web.1]: at new Promise (<anonymous>)
2021-09-04T03:05:42.586057+00:00 app[web.1]: at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
2021-09-04T03:05:42.586057+00:00 app[web.1]: at Mongoose._promiseOrCallback (/app/node_modules/mongoose/lib/index.js:1149:10)
2021-09-04T03:05:42.586058+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:350:20)
2021-09-04T03:05:42.586058+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:18:10)
2021-09-04T03:05:42.586058+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1072:14)
2021-09-04T03:05:42.586059+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
2021-09-04T03:05:42.586059+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:937:32)
2021-09-04T03:05:42.586059+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:778:12)
2021-09-04T03:05:42.586059+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:961:19)
2021-09-04T03:05:42.586059+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:92:18)
2021-09-04T03:05:42.586060+00:00 app[web.1]: at Object.<anonymous> (/app/bin/www:7:11)
2021-09-04T03:05:42.586060+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1072:14)
2021-09-04T03:05:42.586060+00:00 app[web.1]: (Use `node --trace-warnings ...` to show where the warning was created)
2021-09-04T03:05:42.586068+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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
2021-09-04T03:05:42.586093+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.
2021-09-04T03:05:42.648612+00:00 heroku[router]: at=info method=GET path="/" host=pet-store-inventory.herokuapp.com request_id=9de476a1-862c-482e-9522-8748969b11cd fwd="73.249.83.68" dyno=web.1 connect=0ms service=10010ms status=200 bytes=123 protocol=https
2021-09-04T03:05:42.648750+00:00 app[web.1]: GET / 200 10006.287 ms - -
2021-09-04T03:08:24.514610+00:00 heroku[router]: at=info method=GET path="/" host=pet-store-inventory.herokuapp.com request_id=543561e1-e2cd-40fd-8c1d-02df9cecf7df fwd="73.249.83.68" dyno=web.1 connect=0ms service=10011ms status=200 bytes=123 protocol=https
2021-09-04T03:08:24.516838+00:00 app[web.1]: GET / 200 10009.748 ms - -
2021-09-04T03:10:34.790114+00:00 heroku[router]: at=info method=GET path="/" host=pet-store-inventory.herokuapp.com request_id=39c06969-3554-4282-a3d0-7c1f7dc55d14 fwd="73.249.83.68" dyno=web.1 connect=0ms service=10005ms status=200 bytes=123 protocol=https
2021-09-04T03:10:34.790981+00:00 app[web.1]: GET / 200 10003.897 ms - -

2021-09-04T03:15:21.000000+00:00 app[api]: Build succeeded
2021-09-04T03:15:22.315251+00:00 heroku[web.1]: Restarting
2021-09-04T03:15:22.343623+00:00 heroku[web.1]: State changed from up to starting
2021-09-04T03:15:22.982874+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2021-09-04T03:15:23.221890+00:00 heroku[web.1]: Process exited with status 143
2021-09-04T03:15:24.686587+00:00 heroku[web.1]: Starting process with command `node ./bin/www`
2021-09-04T03:15:26.825857+00:00 app[web.1]: Port 15284 is already in use
2021-09-04T03:15:26.885155+00:00 heroku[web.1]: Process exited with status 1
2021-09-04T03:15:26.993248+00:00 heroku[web.1]: State changed from starting to crashed
2021-09-04T03:15:27.021695+00:00 heroku[web.1]: State changed from crashed to starting
2021-09-04T03:15:29.721636+00:00 heroku[web.1]: Starting process with command `node ./bin/www`
2021-09-04T03:15:31.804044+00:00 app[web.1]: Port 39877 is already in use
2021-09-04T03:15:31.855146+00:00 heroku[web.1]: Process exited with status 1
2021-09-04T03:15:31.951365+00:00 heroku[web.1]: State changed from starting to crashed
2021-09-04T03:15:33.528902+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=pet-store-inventory.herokuapp.com request_id=0b6285c6-3999-4ffc-81c4-a4dec690d985 fwd="73.249.83.68" dyno= connect= service= status=503 bytes= protocol=https
2021-09-04T03:16:30.404947+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=pet-store-inventory.herokuapp.com request_id=5fa37910-39e8-4d51-bee1-8ecc2a9bdcad fwd="73.249.83.68" dyno= connect= service= status=503 bytes= protocol=https
1 Like

Sorry to say that I can’t help much, I’ve deployed one or two projects to Heroku and had some hassle setting the env for the connection string, but besides that, everything worked out. If no one else chimes in with an idea, I think your best bet is to comment out large parts of the code to narrow down where the issue is located.

1 Like

I figured out the issue. I needed to add a try…catch to my mongoose connect. I also added 0.0. 0.0/0 to my MongoDB Atlas. Now it works!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.