Heroku, NodeJS, MongoDB, process exited status 1 - node.js

I am doing a nodejs course and am not able to deploy app to heroku. The App stack is nodejs, express, mongodb.
The Problem
I am getting a Process exited with status 1 from heroku after pushing my code.
Here is my app configuration for connecting to database.
module.exports=function(){
let db = config.get('db');
if(process.env.NODE_ENV === 'production'){
db = process.env.MONGODB_URI;
}
mongoose.connect(db)
.then(() => winston.info(`Connected to ${db}...`));
}
my config vars in heroku
MONGODB_URI mongodb+srv://vidlyuser:password#cluster0-b8ezs.mongodb.net/test?retryWrites=true&w=majority
NODE_ENV production
NPM_CONFIG_LOGLEVEL verbose
My greatest challenge is that heroku error logs are not as helpful.
State changed from starting to crashed
Process exited with status 1
heroku logs --tail
2020-03-23T07:10:56.519157+00:00 app[web.1]: npm ERR! Failed at the vidly#1.0.0 start script.
2020-03-23T07:10:56.519289+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-03-23T07:10:56.519715+00:00 app[web.1]: npm verb exit [ 1, true ]
2020-03-23T07:10:56.533850+00:00 app[web.1]: npm timing npm Completed in 1161ms
2020-03-23T07:10:56.534215+00:00 app[web.1]:
2020-03-23T07:10:56.534554+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-03-23T07:10:56.534856+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-03-23T07_10_56_520Z-debug.log
2020-03-23T07:10:56.609864+00:00 heroku[web.1]: State changed from starting to crashed
2020-03-23T07:10:56.592043+00:00 heroku[web.1]: Process exited with status 1
Followed Heroku Node.js app "Process exited with status 1" and error h10. But no change.
this npm ERR! code ELIFECYCLE didnt help either

I think you need to remove the original env file and redo it
heroku config:set MONGODB_URI=mongodb+srv://vidlyuser:password#cluster0-b8ezs.mongodb.net/test?retryWrites=true&w=majority
heroku config:set NPM_CONFIG_LOGLEVEL=verbose

In my effort to fix this issue i learnt that i miss understood the error. i learnt The error npm ERR! Failed at the vidly#1.0.0 start script. usually points to an underlying error. making use of exception logging in my code i was able to discover the actual error and this had to do with a particular npm package.
The solution is npm ERR! Failed at the vidly#1.0.0 start script. usually points to another error.

Related

How to fix npm ERR! code ELIFECYCLE when deploying MEAN app to Heroku

I'm having an issue deploying my backend to Heroku. I'm using the MEAN stack with a Mongo Atlas Database. The app works fine locally. But once I deploy it, it crashes with an npm ERR! code ELIFECYCLE. Apparently, Mongo Atlas requires you to whitelist IP addresses. An article I read said it would work fine if I add my connection string to Heroku environment variables. So I've done so and saved it with the name connectionString. However, this did not work. Does the connection string need a specific name? I've posted my Heroku log below. Note I've tried deleting my node_modules and package.json and reinstalling them as well as changing my node version to 10.x.
2021-03-17T07:22:23.865572+00:00 app[api]: Deploy 2cbf3bbb by user example#example.com
2021-03-17T07:22:23.865572+00:00 app[api]: Release v9 created by user example#example.com
2021-03-17T07:22:24.515688+00:00 heroku[web.1]: State changed from crashed to starting
2021-03-17T07:22:25.000000+00:00 app[api]: Build succeeded
2021-03-17T07:22:27.638401+00:00 heroku[web.1]: Starting process with command `npm start`
2021-03-17T07:22:30.298270+00:00 app[web.1]:
2021-03-17T07:22:30.298283+00:00 app[web.1]: > backend#1.1.1 start /app
2021-03-17T07:22:30.298284+00:00 app[web.1]: > node index.js
2021-03-17T07:22:30.298284+00:00 app[web.1]:
2021-03-17T07:22:31.387500+00:00 app[web.1]: WARNING: NODE_ENV value of 'production' did not match any deployment config file names.
2021-03-17T07:22:31.387844+00:00 app[web.1]: WARNING: See https://github.com/lorenwest/node-config/wiki/Strict-Mode
2021-03-17T07:22:31.931808+00:00 heroku[web.1]: State changed from starting to up
2021-03-17T07:23:01.761238+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-03-17T07:23:01.761850+00:00 app[web.1]: npm ERR! errno 1
2021-03-17T07:23:01.770367+00:00 app[web.1]: npm ERR! backend#1.1.1 start: `node index.js`
2021-03-17T07:23:01.770621+00:00 app[web.1]: npm ERR! Exit status 1
2021-03-17T07:23:01.770728+00:00 app[web.1]: npm ERR!
2021-03-17T07:23:01.772482+00:00 app[web.1]: npm ERR! Failed at the backend#1.1.1 start script.
2021-03-17T07:23:01.772597+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-03-17T07:23:01.781656+00:00 app[web.1]:
2021-03-17T07:23:01.781807+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-03-17T07:23:01.781869+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-03-17T07_23_01_773Z-debug.log
2021-03-17T07:23:01.841833+00:00 heroku[web.1]: Process exited with status 1
2021-03-17T07:23:01.965241+00:00 heroku[web.1]: State changed from up to crashed
2021-03-17T07:23:01.973670+00:00 heroku[web.1]: State changed from crashed to starting
2021-03-17T07:23:06.945061+00:00 heroku[web.1]: Starting process with command `npm start`
2021-03-17T07:23:11.079200+00:00 app[web.1]:
2021-03-17T07:23:11.079239+00:00 app[web.1]: > backend#1.1.1 start /app
2021-03-17T07:23:11.079239+00:00 app[web.1]: > node index.js
2021-03-17T07:23:11.079239+00:00 app[web.1]:
2021-03-17T07:23:12.636407+00:00 app[web.1]: WARNING: NODE_ENV value of 'production' did not match any deployment config file names.
2021-03-17T07:23:12.639137+00:00 app[web.1]: WARNING: See https://github.com/lorenwest/node-config/wiki/Strict-Mode
2021-03-17T07:23:13.442612+00:00 heroku[web.1]: State changed from starting to up
2021-03-17T07:23:43.404828+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-03-17T07:23:43.405294+00:00 app[web.1]: npm ERR! errno 1
2021-03-17T07:23:43.419129+00:00 app[web.1]: npm ERR! backend#1.1.1 start: `node index.js`
2021-03-17T07:23:43.419414+00:00 app[web.1]: npm ERR! Exit status 1
2021-03-17T07:23:43.419741+00:00 app[web.1]: npm ERR!
2021-03-17T07:23:43.420082+00:00 app[web.1]: npm ERR! Failed at the backend#1.1.1 start script.
2021-03-17T07:23:43.420380+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-03-17T07:23:43.437105+00:00 app[web.1]:
2021-03-17T07:23:43.439175+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-03-17T07:23:43.439472+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-03-17T07_23_43_421Z-debug.log
2021-03-17T07:23:43.562438+00:00 heroku[web.1]: Process exited with status 1
2021-03-17T07:23:43.638872+00:00 heroku[web.1]: State changed from up to crashed```
So I figured out the problem. I was using the config module to load the Mongodb Atlas connection string when connecting to my database.
mongoose.connect(config.get('configurationString'), {useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false, useCreateIndex: true}).then(() => winston.info("Connected to MongoDB..."))
I changed config.get('connectionString') to process.env.MONGODB_URL then I added the MONGODB_URL env variable to heroku using heroku config:set MONGODB_URL="<YOUR MONGODB ATLAS CONNECTION STRING>". Also make sure you have a Procfile and add the line web:node index.js

why does secret management tool SecretHub work locally but not in heroku production?

I decided to implement a secret management service (secrethub.io) for a node.js server hosted by Heroku.
Its install process goes something like:
npm install --save-dev #secrethub/cli
secrethub init
(then a credential is given once you signup)
then you adjust main start script to:
secrethub run -- nodemon server.js
now when i run the app locally with npm run start everything is fine, server runs as it should, secrets are injected, all is good. but when i deploy to Heroku, the app crashes immediately on the start script:
server#1.0.0 start /app 2020-09-28T22:42:08.353088+00:00
app[web.1]: > secrethub run -- nodemon server.js
2020-09-28T22:42:08.353088+00:00 app[web.1]:
2020-09-28T22:42:08.469775+00:00 app[web.1]: Encountered an error:
error while processing template file 'secrethub.env': could not find
credential file. Go to https://signup.secrethub.io/ to create an
account or run secrethub init to use an already existing account on
this machine. (secrethub.credential_not_exist)
(run.template_parsing_failed) 2020-09-28T22:42:08.484159+00:00
app[web.1]: npm ERR! code ELIFECYCLE 2020-09-28T22:42:08.484663+00:00
app[web.1]: npm ERR! errno 1 2020-09-28T22:42:08.493367+00:00
app[web.1]: npm ERR! aflare-stripe#1.0.0 start: secrethub run -- nodemon server.js 2020-09-28T22:42:08.493885+00:00 app[web.1]: npm
ERR! Exit status 1 2020-09-28T22:42:08.494399+00:00 app[web.1]: npm
ERR! 2020-09-28T22:42:08.494840+00:00 app[web.1]: npm ERR! Failed at
the aflare-stripe#1.0.0 start script. 2020-09-28T22:42:08.495292+00:00
app[web.1]: npm ERR! This is probably not a problem with npm. There is
likely additional logging output above.
2020-09-28T22:42:08.515466+00:00 app[web.1]:
2020-09-28T22:42:08.516772+00:00 app[web.1]: npm ERR! A complete log
of this run can be found in: 2020-09-28T22:42:08.517179+00:00
app[web.1]: npm ERR!
/app/.npm/_logs/2020-09-28T22_42_08_498Z-debug.log
like i said I've already signed up and everything. Anyone know of any issues deploying to Heroku and using secret management services?
Judging from the following part of the log, it looks like the SecretHub CLI does not have access to a credential:
could not find credential file. Go to https://signup.secrethub.io/ to create an account or run secrethub init to use an already existing account on this machine. (secrethub.credential_not_exist)
You can solve this, by creating a service account for your Heroku app. You can follow this guide to see how. You can configure the resulting credential as the SECRETHUB_CREDENTIAL environment variable in Heroku (see here how).

Azure NodeJS Azure Devops deployment failing but Visual Studio deploy works perfect

We are trying to deploy a NodeJS app to Azure App Service (Linux) and if we deploy this from Visual Studio everything works fine and the site renders perfectly.
Now we create a basic build/Release pipeline and deploying the zip file (Created from build) to the App services on Azure and then if we try to render the site it throws application error (Following is the log of the error):
> 2020-04-15T20:27:47.222887443Z > externalservicestatus#0.0.0 start /home/site/wwwroot
2020-04-15T20:27:47.222895143Z > node ./bin/www
2020-04-15T20:27:47.222899943Z
2020-04-15T20:27:47.371119383Z internal/modules/cjs/loader.js:797
2020-04-15T20:27:47.371195483Z throw err;
2020-04-15T20:27:47.371942583Z ^
2020-04-15T20:27:47.371974683Z
2020-04-15T20:27:47.372042983Z ***Error: Cannot find module '/home/site/wwwroot/bin/www'
2020-04-15T20:27:47.372063083Z at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
2020-04-15T20:27:47.372103483Z at Function.Module._load (internal/modules/cjs/loader.js:687:27)
2020-04-15T20:27:47.372136083Z at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)
2020-04-15T20:27:47.372176983Z at internal/main/run_main_module.js:17:11 {
2020-04-15T20:27:47.372206183Z code: 'MODULE_NOT_FOUND',***
2020-04-15T20:27:47.372292683Z requireStack: []
2020-04-15T20:27:47.372316483Z }
2020-04-15T20:27:47.402670091Z npm ERR! code ELIFECYCLE
2020-04-15T20:27:47.409661993Z npm ERR! errno 1
2020-04-15T20:27:47.411500494Z npm ERR! externalservicestatus#0.0.0 start: `node ./bin/www`
2020-04-15T20:27:47.412151894Z npm ERR! Exit status 1
2020-04-15T20:27:47.412616894Z npm ERR!
2020-04-15T20:27:47.419115996Z npm ERR! Failed at the externalservicestatus#0.0.0 start script.
2020-04-15T20:27:47.419849596Z npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-04-15T20:27:47.432179799Z
2020-04-15T20:27:47.432704699Z npm ERR! A complete log of this run can be found in:
2020-04-15T20:27:47.433290000Z npm ERR! /root/.npm/_logs/2020-04-15T20_27_47_420Z-debug.log
2020-04-15 20:27:48.453 ERROR - Container testexternalapp2_0_6702db49 for site testexternalapp2 has exited, failing site start
2020-04-15 20:27:48.464 ERROR - Container testexternalapp2_0_6702db49 didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.
What I found out is that whenever deployed from Visual Studio "./bin/www" is created and deployed on the App service but whenever deploying from Azure DevOps Release pipeline the "./bin/wwww" is missing and not available. Any help?
This is what I see from Log Stream when deployed from Visual Studio:
> /appsvctmp/volatile/logs/runtime/afbd672b48147e81a539c200a40b91607386719df21a7e51f842abbcd70c89db.log
2020-04-15T17:47:12.057871083Z: [INFO] echo "Done."
2020-04-15T17:47:12.057884183Z: [INFO] PATH="$PATH:/home/site/wwwroot" npm start
2020-04-15T17:47:13.285047383Z: [INFO] Found tar.gz based node_modules.
2020-04-15T17:47:13.295572890Z: [INFO] Removing existing modules directory from root...
2020-04-15T17:47:13.307481412Z: [INFO] Extracting modules...
2020-04-15T17:47:17.392564316Z: [INFO] Done.
2020-04-15T17:47:22.666823807Z: [INFO]
2020-04-15T17:47:22.666850507Z: [INFO] > externalservicestatus#0.0.0 start /home/site/wwwroot
2020-04-15T17:47:22.666855308Z: [INFO] > node ./bin/www
2020-04-15T17:47:22.666858408Z: [INFO]
And When deployed from Azure DevOps this is what I see from the Logs:
2020-04-15T21:17:50.664112070Z npm ERR! errno 1
2020-04-15T21:17:50.664156869Z npm ERR! externalservicestatus#0.0.0 start: `node ./bin/www`
2020-04-15T21:17:50.664174469Z npm ERR! Exit status 1
2020-04-15T21:17:50.664206269Z npm ERR!
2020-04-15T21:17:50.664220669Z npm ERR! Failed at the externalservicestatus#0.0.0 start script.
2020-04-15T21:17:50.664251169Z npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-04-15T21:17:50.713658687Z
2020-04-15T21:17:50.713714987Z npm ERR! A complete log of this run can be found in:
2020-04-15T21:17:50.713837887Z npm ERR! /root/.npm/_logs/2020-04-15T21_17_50_672Z-debug.log
Please download your artifact and look what is inside.
There can be an issue with publishing your files, due to wrong path configuration in your pipeline. If you are missing expected files/folders in this case ./bin/www you probably have some mistake in pipeline and everything is fine on Azure.
In this case I also recommend to add bash: ls your-publish-directory step to check content.

Can't View Express/React App in Heroku (concurrently not found)

I'm having trouble viewing my Node/Express + React project in Heroku. After successfully pushing my project to Heroku, I get a 404 error page when I try to view my app in heroku.
Heroku Logs shows that the concurrently package was not found
I was wondering if anyone can help me figure out why?
Everything works locally. No issues.
I haven't been able to find any solutions. I've tried this:
https://github.com/RickWong/react-isomorphic-starterkit/issues/12
I tried setting an environment variable in heroku with the following suggestion:
heroku config:set NPM_CONFIG_PRODUCTION=false
However, it did not work.
I also found this:
https://github.com/rickbergfalk/sqlpad/issues/359
I've attempted re-installing concurrently twice, in the server folder, as well as in root. But with each instance, I got the same error telling me that concurrently was not found.
Here is the Heroku log:
2019-01-05T04:44:42.843348+00:00 heroku[web.1]: Starting process with command `npm start`
2019-01-05T04:44:45.795355+00:00 heroku[web.1]: Process exited with status 1
2019-01-05T04:44:45.817371+00:00 heroku[web.1]: State changed from starting to crashed
2019-01-05T04:44:45.825275+00:00 heroku[web.1]: State changed from crashed to starting
2019-01-05T04:44:45.691080+00:00 app[web.1]:
2019-01-05T04:44:45.691107+00:00 app[web.1]: > hello_fullstack#1.0.0 start /app
2019-01-05T04:44:45.691110+00:00 app[web.1]: > concurrently -- kill-others "npm run server" "npm run client"
2019-01-05T04:44:45.691112+00:00 app[web.1]:
2019-01-05T04:44:45.699841+00:00 app[web.1]: sh: 1: concurrently: not found
2019-01-05T04:44:45.704281+00:00 app[web.1]: npm ERR! file sh
2019-01-05T04:44:45.704664+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-01-05T04:44:45.704985+00:00 app[web.1]: npm ERR! errno ENOENT
2019-01-05T04:44:45.705300+00:00 app[web.1]: npm ERR! syscall spawn
2019-01-05T04:44:45.706913+00:00 app[web.1]: npm ERR! hello_fullstack#1.0.0 start: `concurrently -- kill-others "npm run server" "npm run client"`
2019-01-05T04:44:45.707140+00:00 app[web.1]: npm ERR! spawn ENOENT
2019-01-05T04:44:45.707475+00:00 app[web.1]: npm ERR!
2019-01-05T04:44:45.707708+00:00 app[web.1]: npm ERR! Failed at the hello_fullstack#1.0.0 start script.
2019-01-05T04:44:45.708000+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-01-05T04:44:45.718125+00:00 app[web.1]:
2019-01-05T04:44:45.718481+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-01-05T04:44:45.718674+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-01-05T04_44_45_709Z-debug.log
Any suggestions?
(Not sure this matters, but my dev environment is in ubuntu, which I'm running inside virtualbox; host os is Windows 8)
I found a solution to my problem.
After struggling with it, I decided to just start over and build a sample react/express app, and see if I could deploy it to heroku. Upon successfully deploying, I compared the code from my sample app and my broken app. It then occurred to me that perhaps the issue was with the commands that I assigned to the heroku-postbuild script in the package.json file of my root folder.
Previously, I had this junk:
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
I changed that to this:
"heroku-postbuild": "cd client && npm install && npm run build"
And, like magic, it worked! I guess I wasn't "building" what I was supposed to build on the heroku side.

While deploying to heroku , I am getting the following error log

I have used Postgresql add-on and NodeJS framework.In .gitignore file , I have already added npm-debug.log.
2016-09-07T23:35:01.785651+00:00 app[web.1]: npm ERR! node server.js
2016-09-07T23:35:01.785817+00:00 app[web.1]: npm ERR! You can get their info via:
2016-09-07T23:35:01.785982+00:00 app[web.1]: npm ERR! npm owner ls version3
2016-09-07T23:35:01.789051+00:00 app[web.1]:
2016-09-07T23:35:01.789307+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-09-07T23:35:01.789464+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2016-09-07T23:35:01.888595+00:00 heroku[web.1]: State changed from starting to crashed
2016-09-07T23:35:01.878834+00:00 heroku[web.1]: Process exited with status 1
Do you have all dependencies listed in your package.json file?
To add a library to package.json,
npm install<libName> --save

Resources