heroku application error, application crashed Node.js - node.js

I have an express application connected to mongoose here is my package.json
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.4",
"cors": "^2.8.5",
"express": "^4.17.1",
"helmet": "^3.21.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.7.4",
"morgan": "^1.9.1"
}
}
and my procfile
web : node app.js
and this is the error i get from the logs
2019-10-15T22:49:24.862621+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/" host=boutique2backend.herokuapp.com request_id=7d85289
5-32ec-4958-84f9-4b6f1c185539 fwd="41.40.131.141" dyno= connect= service= status
=503 bytes= protocol=https
2019-10-15T22:49:25.325894+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/favicon.ico" host=boutique2backend.herokuapp.com request
_id=1aa4b90e-040d-4cc0-9b79-b4cf28b2c804 fwd="41.40.131.141" dyno= connect= serv
ice= status=503 bytes= protocol=https
when i restart the application i get
2019-10-15T22:50:07.470079+00:00 heroku[web.1]: State changed from crashed to st
arting
2019-10-15T22:50:09.525567+00:00 heroku[web.1]: Starting process with command `:
node app.js`
2019-10-15T22:50:11.621514+00:00 heroku[web.1]: Process exited with status 0
2019-10-15T22:50:11.666391+00:00 heroku[web.1]: State changed from starting to c
rashed
I doubly made sure that my port is set to the env variable
const PORT = process.env.PORT || 3002;

This once happened to me and these were the likely issues that were the culprit
I had a npm module called https-localHost
which gives you ssl for when you want to test lets say authentication with facebook, google or any other OAuth
whose solution was to simply uninstall the module or stop using it
I had not set the environment variables
which you can do at your console using this command
heroku config:set myEnvironmentVariable=234234
Since I was using mongodb the application on heroku had no way to connect to my local instance on my pc so I had to supply one from Mlab using again environment variables
I would advice you to use winston
which according to them
winston is designed to be a simple and universal logging library with support for multiple transports. A transport is essentially a storage device for your logs.
It would allow you to store your errors in files which you can access from the console when you either ssh into or from the Heroku dashboard so as to get a better look at your errors and know your source of the problem since looking at the actual heroku logs won't actually show you these errors
cheers!

Related

App won't connect to MongoDB using MongoDB code

I can run everything fine locally, and the app shows up on Heroku (all using the local mongoose db), but if I switch to the MongoDB db, using the code provided by MongoDB, both the local (goorm) and the Heroku sites fail when I do anything that needs to address the db.
The first err that appears in the Heroku log is:
2020-08-08T15:57:45.898855+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-08T15:57:46.903138+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=lit-forest-68974.heroku app.com request_id=a99ca76f-f8a8-4790-bf83-d42c24cc17d7 fwd="77.11.27.47" dyno= connect= service= status=503 bytes= protocol=https
2020-08-08T15:57:47.298492+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=lit-forest-68974.herokuapp.com request_id=cf828829-07cf-4c23-861f-3a123039a66f fwd="77.11.27.47" dyno= connect= service= status=503 bytes= protoco
l=https
I am thinking (hoping) that the issue is something in how I reference the db in my app.js file. I am using:
const MongoClient = require('mongodb').MongoClient;
const uri = "mongodb+srv://NeilGreer:Ng232117#clearport1.sxp3s.mongodb.net/clearport11?retryWrites=true&w=majority";
const client = new MongoClient(uri, { useNewUrlParser: true , useUnifiedTopology: true});
client.connect(err => {
const collection = client.db("test").collection("devices");
// perform actions on the collection object
client.close();
});
Which was the code directly copied from MongoDB.'
Has anyone run into a similar issue?
You're getting H10 error.
No issues found on your MongoDB connect file as it is working well on local.
Please check below items.
Check whether you have added start script in package.json
"scripts": {
"start": "node index.js"
}
Don't set PORT in your code. Heroku will automatically set PORT and can get from environmental variables.
const PORT = process.env.PORT || 5000
Also check your Procfile whether web dyno commands given correctly.

missing script: start & App crashed when deploying app to Heroku

I'm new to coding but currently learning as i want to create a chatbot to my facebook page. Belows are the script i have inside each .js and errors that i came across after that. After i input heroku open, the web shows "Application error
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details."
Hope someone can help me out, a lot of thanks!
index.js
var express = require('express')
var bodyParser = require('body-parser')
var request = require('request')
var app = express()
app.set('port', (process.env.PORT || 5000))
// Process application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({extended: false}))
// Process application/json
app.use(bodyParser.json())
// Index route
app.get('/', function (req, res) {
res.send('Hello world, I am a chat bot')
})
// for Facebook verification
app.get('/webhook/', function (req, res) {
if (req.query['hub.verify_token'] === 'my_voice_is_my_password_verify_me') {
res.send(req.query['hub.challenge'])
}
res.send('Error, wrong token')
})
// Spin up the server
app.listen(app.get('port'), function() {
console.log('running on port', app.get('port'))
})
package.json
{
"name": "node",
"version": "1.0.0",
"description": "facebook chatbot",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "krix",
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.1",
"express": "^4.15.4",
"request": "^2.81.0"
}
}
Procfile.json
web: node index.js
heroku logs:
2017-09-14T13:32:53.277012+00:00 app[api]: Release v2 created by user network.of.eden#gmail.com
2017-09-14T13:32:53.277012+00:00 app[api]: Enable Logplex by user network.of.eden#gmail.com
2017-09-14T13:32:53.049614+00:00 app[api]: Initial release by user network.of.eden#gmail.com
2017-09-14T13:32:53.049614+00:00 app[api]: Release v1 created by user network.of.eden#gmail.com
2017-09-14T13:33:16.000000+00:00 app[api]: Build started by user network.of.eden#gmail.com
2017-09-14T13:33:44.501803+00:00 app[api]: Release v3 created by user network.of.eden#gmail.com
2017-09-14T13:33:44.550885+00:00 app[api]: Scaled to web#1:Free by user network.of.eden#gmail.com
2017-09-14T13:33:44.501803+00:00 app[api]: Deploy 30d98ae9 by user network.of.eden#gmail.com
2017-09-14T13:33:16.000000+00:00 app[api]: Build succeeded
2017-09-14T13:33:47.445193+00:00 heroku[web.1]: Starting process with command `npm start`
2017-09-14T13:33:51.208413+00:00 app[web.1]:
2017-09-14T13:33:51.208690+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2017-09-14T13:33:51.208802+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2017-09-14T13_33_51_189Z-debug.log
2017-09-14T13:33:51.186998+00:00 app[web.1]: npm ERR! missing script: start
2017-09-14T13:33:51.326957+00:00 heroku[web.1]: State changed from starting to crashed
2017-09-14T13:33:51.329410+00:00 heroku[web.1]: State changed from crashed to starting
2017-09-14T13:33:51.312231+00:00 heroku[web.1]: Process exited with status 1
2017-09-14T13:33:53.384440+00:00 heroku[web.1]: Starting process with command `npm start`
2017-09-14T13:33:56.553788+00:00 app[web.1]: npm ERR! missing script: start
2017-09-14T13:33:56.567775+00:00 app[web.1]:
2017-09-14T13:33:56.567944+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2017-09-14T13:33:56.567995+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2017-09-14T13_33_56_555Z-debug.log
2017-09-14T13:33:56.688362+00:00 heroku[web.1]: Process exited with status 1
2017-09-14T13:33:56.703579+00:00 heroku[web.1]: State changed from starting to crashed
2017-09-14T13:34:34.169385+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=boiling-fortress-15768.herokuapp.com request_id=d93942a9-fddf-426c-8604-39aaf8abe6a7 fwd="58.153.46.198" dyno= connect= service= status=503 bytes= protocol=https
2017-09-14T13:34:34.510184+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=boiling-fortress-15768.herokuapp.com request_id=8b2d01d7-56f8-453b-a355-d58c9fd6ca85 fwd="58.153.46.198" dyno= connect= service= status=503 bytes= protocol=https
2017-09-14T13:37:20.203744+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=boiling-fortress-15768.herokuapp.com request_id=884f9ef7-b7f9-4f49-bd57-6b509ec90f6f fwd="58.153.46.198" dyno= connect= service= status=503 bytes= protocol=https
2017-09-14T13:37:20.530728+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=boiling-fortress-15768.herokuapp.com request_id=3ae40dba-5f53-4436-a406-1c45b6bab5af fwd="58.153.46.198" dyno= connect= service= status=503 bytes= protocol=https
I have tried and read through quite a lot of questions others have been asking on github, but i still cannot fix the problem. I learnt the method in setting up the nodejs and heroku server from the following website: https://chatbotsmagazine.com/have-15-minutes-create-your-own-facebook-messenger-bot-481a7db54892
I sincerely hope someone can help me out with the problems, thank you so much!!
The Procfile file name should be just Procfile, and I see that yours seems to be named Procfile.json, could be it.
But as you package.json has the start script, just make sure you have git added all your files and committed them before pushing to Heroku
This may sound repetitive, but believe me it is not. I am doing a course where 100s if not thousands have the same question. Please review following things if you come across this error.
In your package.json file, make sure you have mentioned "start": "node app.js" in scripts and also the "engines under "licence". Here is example code for my package.json which is working now:
{
"name": "todolist-v1",
"version": "1.0.0",
"description": "todolist",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"author": "Armaghan",
"license": "ISC",
"engines": {
"node": "14.15.3"
},
"dependencies": {
"body-parser": "^1.19.0",
"ejs": "^3.1.5",
"express": "^4.17.1",
"jquery": "^3.5.1",
"lodash": "^4.17.20a",
"mongoose": "^5.11.14",
"nodemon": "^2.0.7"
}
}
To make sure you have added the right version of your node, use this command in terminal to reveal your present version of node. node --version
Please make sure your app is listening onto the correct port.
replace app.listen code with following code for heroku app deployement:
let port = process.env.PORT;
if (port == null || port == "") {
port = 3000;
}
app.listen(port, function() {
console.log("Server started succesfully");
});
Make sure you are committing the correct git branch. I was forgetfully commiting a different (expreimental) branch, which did not have the updated changes in package.json file. To check your present git repository branch, use git branch
Once branch revealed, you can switch between branches with git checkout branchname
In my case, I wanted to commit master, so I went inside master first by using git branch master and then actually added the files to git using
git add . (with dot included after a space).
then use git commit -m "your comment"
and finally use following command to push it on Heroku Server again.
git push heroku master
Once the push is completed, it is always a good idea to give it a few minutes before reaching the web app address on internet as it may take a moment to get things up and running.
For some people using MongoDB Atlas, the deployment still fails and the app crashes if you allowed only a single specific IP (your IP only) to access your database cluster at MongoDB Atlas. Therefore, try to change 'Network Access' settings in your atlas account to "Allow access from anywhere". This will get rid of the network-access error sometimes shown in Heroku error logs.
Kind regards,

Heroku deploy error

Hi, I have some problems: I tried to deploy a nodejs app on heroku, but when I try to open it, I get this error :
2017-06-08T16:08:43.221350+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=xmpp-discord.herokuapp.com request_id=6692a6c4-2563-474d-90e2-1657d83c7393 fwd="92.157.13.75" dyno= connect= service= status=503 bytes= protocol=https
2017-06-08T16:08:43.433802+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=xmpp-discord.herokuapp.com request_id=ab1f0f7d-4eed-4948-94e2-bb80fcd9887b fwd="92.157.13.75" dyno= connect= service= status=503 bytes= protocol=https
My app is a bridge between Discord and XMPP: here It's github base: Github but I ran it and setuped it, it does work in local but I want to run the program all day even if my PC isn't on.
What should or could I do?
If you need more infos tell me !
Thanks
It's right there in the logs "missing script 'start'". Either in your procfile or due to Heroku defaults your app is trying to launch using "npm start", but your package.json does not define a start script.
Either update your procfile to the correct start command or add to your package.json, in the "scripts" object something like: "start": "node server.js" or whatever command you normally use to start the app.

MERN app on Heroku

I'm trying to get mern app working on heroku. But right now even fixing of node server would be enough.
This is what i have already done.
Created app in heroku and push my project to it.
Added mLab database link. (running properly on local server)
put dev dependencies on the dependencies.
Tried running "heroku run node server.js" through heroku CLI. Then it logs as server started on port 8080.
But I cannot access the API or the web interface.
My app url = http://travelaround.herokuapp.com
Please note my web application was create using create-react-app
My Logs at heroku,
2017-05-14T17:17:50.113754+00:00 heroku[api.1]: Process exited with status 0
2017-05-14T17:17:52.979224+00:00 heroku[api.1]: Starting process with command `nodemon server.js`
2017-05-14T17:17:53.538796+00:00 heroku[api.1]: State changed from starting to up
2017-05-14T17:17:55.154398+00:00 app[api.1]: [33m[nodemon] 1.11.0[39m
2017-05-14T17:17:55.156364+00:00 app[api.1]: [33m[nodemon] to restart at any time, enter `rs`[39m
2017-05-14T17:17:55.156522+00:00 app[api.1]: [33m[nodemon] watching: *.*[39m
2017-05-14T17:17:55.157062+00:00 app[api.1]: [32m[nodemon] starting `node server.js`[39m
2017-05-14T17:17:55.982045+00:00 app[api.1]: Database connection Established at mongodb://test:asd123#ds139791.mlab.com:39791/travelaround
2017-05-14T17:17:56.008148+00:00 app[api.1]: api running on port 3000
2017-05-15T14:22:19.692618+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=travelaround.herokuapp.com request_id=b46a031e-db9d-4cac-93fa-ffd73f51e5f3 fwd="93.65.70.107" dyno= connect= service= status=503 bytes= protocol=http
2017-05-15T14:22:20.297803+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=travelaround.herokuapp.com request_id=9ca4977c-b45e-4f3e-b98a-1034855e8c4f fwd="93.65.70.107" dyno= connect= service= status=503 bytes= protocol=http
Ok, so from the screenshot of your Heroku dashboard and error, it looks like your dynos are not running. I suggest you compile all of your react code, so you only have static content on your frontend, and then turn on the API dyno, so you can actually curl to it from your react code.

Heroku deployment crashing at start Nodejs

I am trying to deploy my existing NodeJS application to heroku. I followed all the process listed in the documentation.
I wrote this on my procfile:
web: node ./bin/www
but I am constantly getting:
Process exited with status 1
2016-08-08T11:07:54.028983+00:00 heroku[web.1]: State changed from starting to crashed
2016-08-08T11:07:56.852268+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=agile-headland-49936.herokuapp.com request_id=357f1a83-adff-4353-8e6b-6f8166cdb09b fwd="202.166.207.112" dyno= connect= service= status=503 bytes=
web: node ./bin/www this gives me a hint that you are making an Express App. Your package.json might have something like:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node ./bin/www"
}
You can just place web: npm start in your Procfile. This should work. Hope this helps :)

Resources