Hosting an express app on Heroku error with mongoose - node.js

I'm building a mean stack app with ionic 2 and I want to host it on Heroku. The app is finished and runs fine locally and I have it connected to a mLabs database. When I push the app to Heroku I am getting the following error in the logs.
2017-04-10T12:32:15.558949+00:00 app[web.1]: Error: Cannot find module 'mongoose'
2017-04-10T12:32:15.558953+00:00 app[web.1]: at Module._compile (module.js:570:32)
2017-04-10T12:32:15.558954+00:00 app[web.1]: at Object.Module._extensions..js (module.js:579:10)
2017-04-10T12:32:15.558951+00:00 app[web.1]: at Function.Module._load (module.js:417:25)
2017-04-10T12:32:15.558952+00:00 app[web.1]: at require (internal/module.js:20:19)
2017-04-10T12:32:15.558952+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:4:16)
2017-04-10T12:32:15.558951+00:00 app[web.1]: at Module.require (module.js:497:17)
2017-04-10T12:32:15.558954+00:00 app[web.1]: at Module.load (module.js:487:32)
2017-04-10T12:32:15.558955+00:00 app[web.1]: at Function.Module._load (module.js:438:3)
2017-04-10T12:32:15.558955+00:00 app[web.1]: at tryModuleLoad (module.js:446:12)
2017-04-10T12:32:15.558950+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:469:15)
2017-04-10T12:32:15.567486+00:00 app[web.1]:
2017-04-10T12:32:15.577504+00:00 app[web.1]: npm ERR! Linux 3.13.0-112-generic
2017-04-10T12:32:15.577867+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2017-04-10T12:32:15.578113+00:00 app[web.1]: npm ERR! node v6.10.2
2017-04-10T12:32:15.578341+00:00 app[web.1]: npm ERR! npm v3.10.10
2017-04-10T12:32:15.578578+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-04-10T12:32:15.578785+00:00 app[web.1]: npm ERR! ionic-hello-world# start: `node server.js`
2017-04-10T12:32:15.578954+00:00 app[web.1]: npm ERR! Exit status 1
2017-04-10T12:32:15.579249+00:00 app[web.1]: npm ERR!
2017-04-10T12:32:15.579426+00:00 app[web.1]: npm ERR! Failed at the ionic-hello-world# start script 'node server.js'.
2017-04-10T12:32:15.579621+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2017-04-10T12:32:15.579920+00:00 app[web.1]: npm ERR! not with npm itself.
2017-04-10T12:32:15.579746+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the ionic-hello-world package,
2017-04-10T12:32:15.580101+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2017-04-10T12:32:15.580265+00:00 app[web.1]: npm ERR! node server.js
2017-04-10T12:32:15.580757+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2017-04-10T12:32:15.580428+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2017-04-10T12:32:15.580601+00:00 app[web.1]: npm ERR! npm bugs ionic-hello-world
2017-04-10T12:32:15.580878+00:00 app[web.1]: npm ERR! npm owner ls ionic-hello-world
2017-04-10T12:32:15.580993+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-04-10T12:32:15.588769+00:00 app[web.1]:
2017-04-10T12:32:15.589345+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-04-10T12:32:15.589646+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2017-04-10T12:32:15.679397+00:00 heroku[web.1]: State changed from starting to crashed
2017-04-10T12:32:15.680194+00:00 heroku[web.1]: State changed from crashed to starting
2017-04-10T12:32:15.673049+00:00 heroku[web.1]: Process exited with status 1
2017-04-10T12:32:18.568796+00:00 heroku[web.1]: Starting process with command `npm start`
2017-04-10T12:32:21.743026+00:00 app[web.1]:
2017-04-10T12:32:21.743041+00:00 app[web.1]: > ionic-hello-world# start /app
2017-04-10T12:32:21.743042+00:00 app[web.1]: > node server.js
2017-04-10T12:32:21.743042+00:00 app[web.1]:
2017-04-10T12:32:22.058223+00:00 app[web.1]: module.js:471
2017-04-10T12:32:22.058237+00:00 app[web.1]: ^
2017-04-10T12:32:22.058236+00:00 app[web.1]: throw err;
2017-04-10T12:32:22.058239+00:00 app[web.1]: Error: Cannot find module 'mongoose'
2017-04-10T12:32:22.058238+00:00 app[web.1]:
2017-04-10T12:32:22.058241+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:469:15)
2017-04-10T12:32:22.058242+00:00 app[web.1]: at Function.Module._load (module.js:417:25)
2017-04-10T12:32:22.058242+00:00 app[web.1]: at Module.require (module.js:497:17)
2017-04-10T12:32:22.058243+00:00 app[web.1]: at require (internal/module.js:20:19)
2017-04-10T12:32:22.058243+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:4:16)
2017-04-10T12:32:22.058244+00:00 app[web.1]: at Module._compile (module.js:570:32)
2017-04-10T12:32:22.058245+00:00 app[web.1]: at Object.Module._extensions..js (module.js:579:10)
2017-04-10T12:32:22.058245+00:00 app[web.1]: at Module.load (module.js:487:32)
2017-04-10T12:32:22.058246+00:00 app[web.1]: at tryModuleLoad (module.js:446:12)
2017-04-10T12:32:22.058246+00:00 app[web.1]: at Function.Module._load (module.js:438:3)
2017-04-10T12:32:22.067921+00:00 app[web.1]:
2017-04-10T12:32:22.080492+00:00 app[web.1]: npm ERR! Linux 3.13.0-112-generic
2017-04-10T12:32:22.080827+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2017-04-10T12:32:22.080991+00:00 app[web.1]: npm ERR! node v6.10.2
2017-04-10T12:32:22.081154+00:00 app[web.1]: npm ERR! npm v3.10.10
2017-04-10T12:32:22.081323+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-04-10T12:32:22.081657+00:00 app[web.1]: npm ERR! Exit status 1
2017-04-10T12:32:22.081825+00:00 app[web.1]: npm ERR!
2017-04-10T12:32:22.081993+00:00 app[web.1]: npm ERR! Failed at the ionic-hello-world# start script 'node server.js'.
2017-04-10T12:32:22.082162+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2017-04-10T12:32:22.081490+00:00 app[web.1]: npm ERR! ionic-hello-world# start: `node server.js`
2017-04-10T12:32:22.082332+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the ionic-hello-world package,
2017-04-10T12:32:22.082335+00:00 app[web.1]: npm ERR! not with npm itself.
2017-04-10T12:32:22.082498+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2017-04-10T12:32:22.082666+00:00 app[web.1]: npm ERR! node server.js
2017-04-10T12:32:22.082832+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2017-04-10T12:32:22.083001+00:00 app[web.1]: npm ERR! npm bugs ionic-hello-world
2017-04-10T12:32:22.083168+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2017-04-10T12:32:22.083170+00:00 app[web.1]: npm ERR! npm owner ls ionic-hello-world
2017-04-10T12:32:22.083338+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-04-10T12:32:22.092234+00:00 app[web.1]:
2017-04-10T12:32:22.092236+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-04-10T12:32:22.092237+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2017-04-10T12:32:22.188511+00:00 heroku[web.1]: Process exited with status 1
2017-04-10T12:32:22.201942+00:00 heroku[web.1]: State changed from starting to crashed
2017-04-10T12:32:50.415338+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=dry-retreat-69141.herokuapp.com request_id=898a0974-f3eb-47b2-a7ca-77a37cf99131 fwd="193.1.57.4" dyno= connect= service= status=503 bytes= protocol=https
2017-04-10T12:35:00.000000+00:00 app[api]: Build started by user alanmurphy1995#gmail.com
2017-04-10T12:36:27.620672+00:00 app[api]: Release v6 created by user alanmurphy1995#gmail.com
2017-04-10T12:36:27.620672+00:00 app[api]: Deploy 9f02cb4 by user alanmurphy1995#gmail.com
2017-04-10T12:36:27.804049+00:00 heroku[web.1]: State changed from crashed to starting
2017-04-10T12:36:27.782474+00:00 app[api]: Release v6 created by user alanmurphy1995#gmail.com
2017-04-10T12:35:00.000000+00:00 app[api]: Build succeeded
2017-04-10T12:36:33.381932+00:00 heroku[web.1]: Starting process with command `npm start`
2017-04-10T12:36:36.544686+00:00 app[web.1]:
2017-04-10T12:36:36.544709+00:00 app[web.1]: > ionic-hello-world# start /app
2017-04-10T12:36:36.544710+00:00 app[web.1]: > node server.js
2017-04-10T12:36:36.544711+00:00 app[web.1]:
2017-04-10T12:36:37.082619+00:00 app[web.1]: App listening on port 8080
2017-04-10T12:37:33.784488+00:00 app[web.1]: Error waiting for process to terminate: No child processes
2017-04-10T12:37:33.760270+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2017-04-10T12:37:33.760270+00:00 heroku[web.1]: Stopping process with SIGKILL
2017-04-10T12:37:33.878656+00:00 heroku[web.1]: Process exited with status 22
2017-04-10T12:37:33.889982+00:00 heroku[web.1]: State changed from starting to crashed
2017-04-10T12:37:34.773926+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=dry-retreat-69141.herokuapp.com request_id=6ba08c4e-a269-4530-b0db-192da56e2724 fwd="193.1.57.4" dyno= connect= service= status=503 bytes= protocol=https
For reference this is my server.js file
// Set up
var express = require('express');
var app = express(); // create our app w/ express
var mongoose = require('mongoose'); // mongoose for mongodb
var morgan = require('morgan'); // log requests to the console (express4)
var bodyParser = require('body-parser'); // pull information from HTML POST (express4)
var methodOverride = require('method-override'); // simulate DELETE and PUT (express4)
var cors = require('cors');
// Configuration
//mongoose.connect('mongodb://localhost/reviewking');
mongoose.connect('Connecting to mLabs here URI not included for security reasons');
app.use(morgan('dev')); // log every request to the console
app.use(bodyParser.urlencoded({'extended':'true'})); // parse application/x-www-form-urlencoded
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
app.use(methodOverride());
app.use(cors());
app.use(express.static("www")); // Our Ionic app build is in the www folder (kept up-to-date by the Ionic CLI using 'ionic serve')
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'DELETE, PUT');
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
// Models
var Review = mongoose.model('Review', {
title: String,
description: String,
rating: Number
});
// Routes
// Get reviews
app.get('/api/reviews', function(req, res) {
console.log("fetching reviews");
// use mongoose to get all reviews in the database
Review.find(function(err, reviews) {
// if there is an error retrieving, send the error. nothing after res.send(err) will execute
if (err)
res.send(err)
res.json(reviews); // return all reviews in JSON format
});
});
// create review and send back all reviews after creation
app.post('/api/reviews', function(req, res) {
console.log("creating review");
// create a review, information comes from request from Ionic
Review.create({
title : req.body.title,
description : req.body.description,
rating: req.body.rating,
done : false
}, function(err, review) {
if (err)
res.send(err);
// get and return all the reviews after you create another
Review.find(function(err, reviews) {
if (err)
res.send(err)
res.json(reviews);
});
});
});
// delete a review
app.delete('/api/reviews/:review_id', function(req, res) {
Review.remove({
_id : req.params.review_id
}, function(err, review) {
});
});
// listen (start app with node server.js) ======================================
app.listen(8080);
console.log("App listening on port 8080");
And this is my package.json file.
{
"name": "ionic-hello-world",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve",
"start": "node server.js"
},
"dependencies": {
"#angular/common": "2.2.1",
"#angular/compiler": "2.2.1",
"#angular/compiler-cli": "2.2.1",
"#angular/core": "2.2.1",
"#angular/forms": "2.2.1",
"#angular/http": "2.2.1",
"#angular/platform-browser": "2.2.1",
"#angular/platform-browser-dynamic": "2.2.1",
"#angular/platform-server": "2.2.1",
"#ionic/storage": "1.1.7",
"#types/cordova-plugin-network-information": "0.0.3",
"angularfire2": "^2.0.0-beta.6",
"firebase": "^3.3.0",
"ionic-angular": "2.1.0",
"ionic-native": "2.4.1",
"ionicons": "3.0.0",
"rxjs": "5.0.0-beta.12",
"sw-toolbox": "3.4.0",
"zone.js": "0.6.26",
"#ionic/app-scripts": "1.1.3",
"typescript": "2.0.9",
"mongoose": "^4.6.2",
"body-parser": "^1.15.2",
"cors": "^2.8.0",
"del": "2.2.0",
"express": "^4.14.0",
"http": "0.0.0",
"method-override": "^2.3.6",
"morgan": "^1.7.0",
"superlogin": "^0.6.1"
},
"devDependencies": {
"#ionic/app-scripts": "1.1.3",
"typescript": "2.0.9",
"mongoose": "^4.6.2",
"body-parser": "^1.15.2",
"cors": "^2.8.0",
"del": "2.2.0",
"express": "^4.14.0",
"http": "0.0.0",
"method-override": "^2.3.6",
"morgan": "^1.7.0",
"superlogin": "^0.6.1"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-console",
"cordova-plugin-statusbar",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": [],
"description": "ReviewApp: An Ionic project"
}
Any help with this error or a solution around this so I can push a working app to Heroku would help greatly.

Removing mongoose from devDependencies should fix it.
Explanation: mongoose is listed twice in package.json - once in dependencies and once in devDependencies, which don't get installed by Heroku.
I also suggest you alphabetize those dependency lists so that this kind of issue is easier to catch in the future.

Related

Error while deploying node.js application to heroku (cannot find module dotenv, and npm ERR! errno 1)

I'm trying to upload my first node.js application to heroku. Build is showing successful, but the application cannot be opened in browser. Here is the logs tail of the deployment. I'm not quite sure where the problem(s) lie(s). All localhost routes are actually working when tested with postman. I'm using express generator, so the PORT is declared in .bin/www. I'm also using .env. I'm a bit lost about where to look next. Any suggestions? Many thanks!
2021-01-11T22:10:14.214188+00:00 app[web.1]: > finale-backend#0.0.0 start /app
2021-01-11T22:10:14.214189+00:00 app[web.1]: > node ./bin/www
2021-01-11T22:10:14.214189+00:00 app[web.1]:
2021-01-11T22:10:14.285451+00:00 app[web.1]: internal/modules/cjs/loader.js:818
2021-01-11T22:10:14.285453+00:00 app[web.1]: throw err;
2021-01-11T22:10:14.285453+00:00 app[web.1]: ^
2021-01-11T22:10:14.285454+00:00 app[web.1]:
2021-01-11T22:10:14.285454+00:00 app[web.1]: Error: Cannot find module 'dotenv'
2021-01-11T22:10:14.285454+00:00 app[web.1]: Require stack:
2021-01-11T22:10:14.285455+00:00 app[web.1]: - /app/app.js
2021-01-11T22:10:14.285455+00:00 app[web.1]: - /app/bin/www
2021-01-11T22:10:14.285456+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
2021-01-11T22:10:14.285456+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:667:27)
2021-01-11T22:10:14.285457+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:887:19)
2021-01-11T22:10:14.285457+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2021-01-11T22:10:14.285458+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:1:1)
2021-01-11T22:10:14.285458+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:999:30)
2021-01-11T22:10:14.285459+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
2021-01-11T22:10:14.285459+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:863:32)
2021-01-11T22:10:14.285459+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:708:14)
2021-01-11T22:10:14.285460+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:887:19) {
2021-01-11T22:10:14.285460+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-01-11T22:10:14.285461+00:00 app[web.1]: requireStack: [ '/app/app.js', '/app/bin/www' ]
2021-01-11T22:10:14.285461+00:00 app[web.1]: }
2021-01-11T22:10:14.301983+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-01-11T22:10:14.302357+00:00 app[web.1]: npm ERR! errno 1
2021-01-11T22:10:14.309690+00:00 app[web.1]: npm ERR! finale-backend#0.0.0 start: `node ./bin/www`
2021-01-11T22:10:14.309804+00:00 app[web.1]: npm ERR! Exit status 1
2021-01-11T22:10:14.309965+00:00 app[web.1]: npm ERR!
2021-01-11T22:10:14.310034+00:00 app[web.1]: npm ERR! Failed at the finale-backend#0.0.0 start script.
2021-01-11T22:10:14.310119+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-01-11T22:10:14.317026+00:00 app[web.1]:
2021-01-11T22:10:14.317243+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-01-11T22:10:14.317339+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-01-11T22_10_14_310Z-debug.log
2021-01-11T22:10:14.361923+00:00 heroku[web.1]: Process exited with status 1
2021-01-11T22:10:14.435764+00:00 heroku[web.1]: State changed from starting to crashed
2021-01-11T22:10:14.439118+00:00 heroku[web.1]: State changed from crashed to starting
2021-01-11T22:10:16.805923+00:00 heroku[web.1]: Starting process with command `npm start`
2021-01-11T22:10:19.751944+00:00 app[web.1]:
2021-01-11T22:10:19.751961+00:00 app[web.1]: > finale-backend#0.0.0 start /app
2021-01-11T22:10:19.751962+00:00 app[web.1]: > node ./bin/www
2021-01-11T22:10:19.751963+00:00 app[web.1]:
2021-01-11T22:10:19.808881+00:00 app[web.1]: internal/modules/cjs/loader.js:818
2021-01-11T22:10:19.808883+00:00 app[web.1]: throw err;
2021-01-11T22:10:19.808883+00:00 app[web.1]: ^
2021-01-11T22:10:19.808883+00:00 app[web.1]:
2021-01-11T22:10:19.808884+00:00 app[web.1]: Error: Cannot find module 'dotenv'
2021-01-11T22:10:19.808884+00:00 app[web.1]: Require stack:
2021-01-11T22:10:19.808884+00:00 app[web.1]: - /app/app.js
2021-01-11T22:10:19.808885+00:00 app[web.1]: - /app/bin/www
2021-01-11T22:10:19.808885+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
2021-01-11T22:10:19.808885+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:667:27)
2021-01-11T22:10:19.808886+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:887:19)
2021-01-11T22:10:19.808886+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2021-01-11T22:10:19.808887+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:1:1)
2021-01-11T22:10:19.808887+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:999:30)
2021-01-11T22:10:19.808887+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
2021-01-11T22:10:19.808888+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:863:32)
2021-01-11T22:10:19.808888+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:708:14)
2021-01-11T22:10:19.808889+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:887:19) {
2021-01-11T22:10:19.808889+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-01-11T22:10:19.808889+00:00 app[web.1]: requireStack: [ '/app/app.js', '/app/bin/www' ]
2021-01-11T22:10:19.808890+00:00 app[web.1]: }
2021-01-11T22:10:19.834122+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-01-11T22:10:19.834754+00:00 app[web.1]: npm ERR! errno 1
2021-01-11T22:10:19.843644+00:00 app[web.1]: npm ERR! finale-backend#0.0.0 start: `node ./bin/www`
2021-01-11T22:10:19.843996+00:00 app[web.1]: npm ERR! Exit status 1
2021-01-11T22:10:19.844353+00:00 app[web.1]: npm ERR!
2021-01-11T22:10:19.844619+00:00 app[web.1]: npm ERR! Failed at the finale-backend#0.0.0 start script.
2021-01-11T22:10:19.844914+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-01-11T22:10:19.858827+00:00 app[web.1]:
2021-01-11T22:10:19.859298+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-01-11T22:10:19.859536+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-01-11T22_10_19_845Z-debug.log
2021-01-11T22:10:19.946324+00:00 heroku[web.1]: Process exited with status 1
2021-01-11T22:10:20.030800+00:00 heroku[web.1]: State changed from starting to crashed
2021-01-11T22:10:22.579029+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=XXXXXX.herokuapp.com request_id=28ed0f16-48b7-4edb-a4d4-bf5af57518a5 fwd="91.106.154.160" dyno= connect= service= status=503 bytes= protocol=https
2021-01-11T22:10:23.309377+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=XXXXXX.herokuapp.com request_id=967010fc-984e-49c7-a73e-9d9758907f49 fwd="91.106.154.160" dyno= connect= service= status=503 bytes= protocol=https
My package json looks like this:
{
"name": "finale-backend",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www",
"dev": "nodemon ./bin/www"
},
"dependencies": {
"bcrypt": "^5.0.0",
"body-parser": "^1.19.0",
"cookie-parser": "~1.4.4",
"cors": "^2.8.5",
"debug": "~2.6.9",
"express": "~4.16.1",
"helmet": "^4.3.1",
"jsonwebtoken": "^8.5.1",
"logger": "0.0.1",
"morgan": "~1.9.1",
"nodemon": "^2.0.7",
"pg": "^8.5.1"
},
"devDependencies": {
"dotenv": "^8.2.0"
},
"engines": {
"node": "12.x"
}
}
And I require dotenv in my entry point app.js like this
require('dotenv').config();
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const cors = require('cors')
It seems like Heroku is not installing devDependencies by default. You may want to move dotenv to dependencies in your package.json and try again.
If you don't need dotenv in your production environment, you may want to remove the require altogether and use a different command to run your development server, as described here:
https://www.npmjs.com/package/dotenv#preload
node -r dotenv/config your_script.js
This will prevent your server from crashing in production when the dotenv dependency is not found on Heroku.
The reason because you are using dotenv in devDependencies. Change dotenv dependency to dependencies like this:
"dependencies": {
...,
"dotenv": "^8.2.0"
}

Heroku errors when deploying node-react app

I am deploying a fullstack react/express app to Heroku, it has managed to deploy. There are multiple errors in the Heroku logs which I have cannot seem to understand/figure out. I also have a Procfile with web: node server.js
I have tried to clear cache - delete node_modules and package.json then npm install again but this has not made a difference.
Heroku Logs
2020-11-15T13:08:12.713935+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:724:14)
2020-11-15T13:08:12.713935+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
2020-11-15T13:08:12.713935+00:00 app[web.1]: at internal/main/run_main_module.js:17:47
2020-11-15T13:08:12.783289+00:00 heroku[web.1]: Process exited with status 1
2020-11-15T13:08:12.818062+00:00 heroku[web.1]: State changed from starting to crashed
2020-11-15T13:08:12.826070+00:00 heroku[web.1]: State changed from crashed to starting
2020-11-15T13:08:21.448256+00:00 heroku[web.1]: Starting process with command `node server.js`
2020-11-15T13:08:24.324135+00:00 app[web.1]: /app/node_modules/mongoose/lib/connection.js:669
2020-11-15T13:08:24.324170+00:00 app[web.1]: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' +
2020-11-15T13:08:24.324175+00:00 app[web.1]: ^
2020-11-15T13:08:24.324175+00:00 app[web.1]:
2020-11-15T13:08:24.324180+00:00 app[web.1]: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
2020-11-15T13:08:24.324185+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:669:11)
2020-11-15T13:08:24.324185+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:342:10
2020-11-15T13:08:24.324190+00:00 app[web.1]: at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:9:12)
2020-11-15T13:08:24.324190+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:341:10)
2020-11-15T13:08:24.324190+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:18:10)
2020-11-15T13:08:24.324191+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1015:30)
2020-11-15T13:08:24.324191+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
2020-11-15T13:08:24.324191+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:879:32)
2020-11-15T13:08:24.324191+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:724:14)
2020-11-15T13:08:24.324192+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
2020-11-15T13:08:24.324196+00:00 app[web.1]: at internal/main/run_main_module.js:17:47
2020-11-15T13:08:24.418110+00:00 heroku[web.1]: Process exited with status 1
2020-11-15T13:08:24.454083+00:00 heroku[web.1]: State changed from starting to crashed
2020-11-15T13:23:24.786742+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=obscure-journey-43421.herokuapp.com request_id=aa6c54d3-cfe3-4f74-b4c5-93018f00ba97 fwd="84.9.66.95" dyno= connect= service= status=503 bytes= protocol=https
2020-11-15T13:23:26.240301+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=obscure-journey-43421.herokuapp.com request_id=ec07ad1c-091f-4e53-b50d-9632b66dd2d4 fwd="84.9.66.95" dyno= connect= service= status=503 bytes= protocol=https
2020-11-15T13:27:28.000000+00:00 app[api]: Build started by user peterjameslewis4#hotmail.com
2020-11-15T13:29:08.458958+00:00 app[api]: Deploy 12d81f3b by user peterjameslewis4#hotmail.com
2020-11-15T13:29:08.458958+00:00 app[api]: Release v12 created by user peterjameslewis4#hotmail.com
2020-11-15T13:29:08.625747+00:00 heroku[web.1]: State changed from crashed to starting
2020-11-15T13:29:09.000000+00:00 app[api]: Build succeeded
2020-11-15T13:29:17.927953+00:00 heroku[web.1]: Starting process with command `npm start`
2020-11-15T13:29:20.083139+00:00 app[web.1]:
2020-11-15T13:29:20.083155+00:00 app[web.1]: > movie-database#1.0.0 start /app
2020-11-15T13:29:20.083155+00:00 app[web.1]: > node server.js
2020-11-15T13:29:20.083155+00:00 app[web.1]:
2020-11-15T13:29:20.795200+00:00 app[web.1]: /app/node_modules/mongoose/lib/connection.js:669
2020-11-15T13:29:20.795248+00:00 app[web.1]: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' +
2020-11-15T13:29:20.795250+00:00 app[web.1]: ^
2020-11-15T13:29:20.795250+00:00 app[web.1]:
2020-11-15T13:29:20.795251+00:00 app[web.1]: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
2020-11-15T13:29:20.795252+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:669:11)
2020-11-15T13:29:20.795254+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:342:10
2020-11-15T13:29:20.795254+00:00 app[web.1]: at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:9:12)
2020-11-15T13:29:20.795255+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:341:10)
2020-11-15T13:29:20.795255+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:18:10)
2020-11-15T13:29:20.795255+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1015:30)
2020-11-15T13:29:20.795256+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
2020-11-15T13:29:20.795256+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:879:32)
2020-11-15T13:29:20.795256+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:724:14)
2020-11-15T13:29:20.795257+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
2020-11-15T13:29:20.795258+00:00 app[web.1]: at internal/main/run_main_module.js:17:47
2020-11-15T13:29:20.810114+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-11-15T13:29:20.810451+00:00 app[web.1]: npm ERR! errno 1
2020-11-15T13:29:20.817598+00:00 app[web.1]: npm ERR! movie-database#1.0.0 start: `node server.js`
2020-11-15T13:29:20.817850+00:00 app[web.1]: npm ERR! Exit status 1
2020-11-15T13:29:20.818099+00:00 app[web.1]: npm ERR!
2020-11-15T13:29:20.818312+00:00 app[web.1]: npm ERR! Failed at the movie-database#1.0.0 start script.
2020-11-15T13:29:20.818490+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-11-15T13:29:20.827750+00:00 app[web.1]:
2020-11-15T13:29:20.828041+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-11-15T13:29:20.828210+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-11-15T13_29_20_819Z-debug.log
2020-11-15T13:29:20.877545+00:00 heroku[web.1]: Process exited with status 1
2020-11-15T13:29:20.913439+00:00 heroku[web.1]: State changed from starting to crashed
2020-11-15T13:29:20.917070+00:00 heroku[web.1]: State changed from crashed to starting
2020-11-15T13:29:33.460653+00:00 heroku[web.1]: Starting process with command `npm start`
2020-11-15T13:29:36.844587+00:00 app[web.1]:
2020-11-15T13:29:36.844630+00:00 app[web.1]: > movie-database#1.0.0 start /app
2020-11-15T13:29:36.844631+00:00 app[web.1]: > node server.js
2020-11-15T13:29:36.844631+00:00 app[web.1]:
2020-11-15T13:29:38.011159+00:00 app[web.1]: /app/node_modules/mongoose/lib/connection.js:669
2020-11-15T13:29:38.011219+00:00 app[web.1]: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' +
2020-11-15T13:29:38.011220+00:00 app[web.1]: ^
2020-11-15T13:29:38.011220+00:00 app[web.1]:
2020-11-15T13:29:38.011224+00:00 app[web.1]: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
2020-11-15T13:29:38.011224+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:669:11)
2020-11-15T13:29:38.011225+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:342:10
2020-11-15T13:29:38.011226+00:00 app[web.1]: at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:9:12)
2020-11-15T13:29:38.011226+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:341:10)
2020-11-15T13:29:38.011226+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:18:10)
2020-11-15T13:29:38.011227+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1015:30)
2020-11-15T13:29:38.011227+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
2020-11-15T13:29:38.011227+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:879:32)
2020-11-15T13:29:38.011228+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:724:14)
2020-11-15T13:29:38.011228+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
2020-11-15T13:29:38.011229+00:00 app[web.1]: at internal/main/run_main_module.js:17:47
2020-11-15T13:29:38.046555+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-11-15T13:29:38.047758+00:00 app[web.1]: npm ERR! errno 1
2020-11-15T13:29:38.059446+00:00 app[web.1]: npm ERR! movie-database#1.0.0 start: node server.js
2020-11-15T13:29:38.059681+00:00 app[web.1]: npm ERR! Exit status 1
2020-11-15T13:29:38.059955+00:00 app[web.1]: npm ERR!
2020-11-15T13:29:38.060192+00:00 app[web.1]: npm ERR! Failed at the movie-database#1.0.0 start script.
2020-11-15T13:29:38.060432+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-11-15T13:29:38.096793+00:00 app[web.1]:
2020-11-15T13:29:38.097273+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-11-15T13:29:38.097587+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-11-15T13_29_38_061Z-debug.log
2020-11-15T13:29:38.193702+00:00 heroku[web.1]: Process exited with status 1
2020-11-15T13:29:38.242866+00:00 heroku[web.1]: State changed from starting to crashed
Server.js
const express = require('express');
const app = express();
const path = require('path');
const cors = require('cors');
const port = process.env.PORT || 5000;
const dotenv = require('dotenv');
const mongoose = require('mongoose');
// Auth Routes
const authRoute = require('./routes/auth');
dotenv.config();
//Connect to DB
mongoose.connect(process.env.DB_CONNECT,
{ useNewUrlParser: true, useUnifiedTopology: true },
() => console.log('connected to DB!')
);
// Serve static files from the React app
app.use(express.static(path.join(__dirname, 'client/build/')));
// Middleware
app.use(express.json());
app.use(cors());
// Put all API endpoints under '/api'
app.use('/api', authRoute)
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname + '/client/build/index.html'));
});
app.listen(port, () => {
console.log(`Listening on port ${port}`);
});
Package.json
{
"name": "movie-database",
"version": "1.0.0",
"description": "Small application created with React.js, react router and the movie database to showcase all latest, upcoming and most popular movies.",
"main": "server.js",
"scripts": {
"start": "node server.js",
"heroku-postbuild": "cd client && npm install && npm run build"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^5.0.0",
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"joi": "^17.3.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.20",
"mongoose": "^5.10.12",
"nodemon": "^2.0.6",
"password-generator": "^2.3.2",
"serve": "^11.3.2"
}
}
I cannot figure out what is going wrong?

Hosting Discord Bot through Heroku, EADDRINUSE error repeating after trying previous suggestions

I'm trying to host a Discord bot for the first time through Heroku (also my first time using the site). It was running perfectly locally, but I started receiving errors in regards to the $PORT once I went online. When I looked that up, I saw I needed to listen to the server in order for the port to stick, but every attempt I've done results in the EADDRINUSE error. I've looked over and tried many examples through these previous answers here and here, deleted modules and reinstalled them countless times, ended node.exe processes before booting up, but I keep running into the error. I must be missing something but I can't figure it out and I feel like I'm just running in circles. Any help would be appreciated.
The error report:
2020-07-28T21:24:01.605923+00:00 heroku[web.1]: Starting process with command `npm start`
2020-07-28T21:24:03.399990+00:00 app[web.1]:
2020-07-28T21:24:03.400006+00:00 app[web.1]: > bot#1.0.0 start /app
2020-07-28T21:24:03.400006+00:00 app[web.1]: > node bot.js
2020-07-28T21:24:03.400006+00:00 app[web.1]:
2020-07-28T21:24:04.323323+00:00 app[web.1]: Ready!
2020-07-28T21:24:06.981374+00:00 app[web.1]: Listening on 50667
2020-07-28T21:24:07.141720+00:00 app[web.1]: events.js:292
2020-07-28T21:24:07.141721+00:00 app[web.1]: throw er; // Unhandled 'error' event
2020-07-28T21:24:07.141722+00:00 app[web.1]: ^
2020-07-28T21:24:07.141722+00:00 app[web.1]:
2020-07-28T21:24:07.141724+00:00 app[web.1]: Error: listen EADDRINUSE: address already in use :::50667
2020-07-28T21:24:07.141725+00:00 app[web.1]: at Server.setupListenHandle [as _listen2] (net.js:1313:16)
2020-07-28T21:24:07.141725+00:00 app[web.1]: at listenInCluster (net.js:1361:12)
2020-07-28T21:24:07.141726+00:00 app[web.1]: at Server.listen (net.js:1447:7)
2020-07-28T21:24:07.141727+00:00 app[web.1]: at Function.listen (/app/node_modules/express/lib/application.js:618:24)
2020-07-28T21:24:07.141727+00:00 app[web.1]: at Client.<anonymous> (/app/bot.js:21075:4)
2020-07-28T21:24:07.141727+00:00 app[web.1]: at Client.emit (events.js:315:20)
2020-07-28T21:24:07.141743+00:00 app[web.1]: at MessageCreateAction.handle (/app/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
2020-07-28T21:24:07.141745+00:00 app[web.1]: at Object.module.exports [as MESSAGE_CREATE] (/app/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
2020-07-28T21:24:07.141752+00:00 app[web.1]: at WebSocketManager.handlePacket (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:386:31)
2020-07-28T21:24:07.141752+00:00 app[web.1]: at WebSocketShard.onPacket (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:436:22)
2020-07-28T21:24:07.141753+00:00 app[web.1]: Emitted 'error' event on Server instance at:
2020-07-28T21:24:07.141753+00:00 app[web.1]: at emitErrorNT (net.js:1340:8)
2020-07-28T21:24:07.141753+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:84:21) {
2020-07-28T21:24:07.141754+00:00 app[web.1]: code: 'EADDRINUSE',
2020-07-28T21:24:07.141754+00:00 app[web.1]: errno: 'EADDRINUSE',
2020-07-28T21:24:07.141755+00:00 app[web.1]: syscall: 'listen',
2020-07-28T21:24:07.141755+00:00 app[web.1]: address: '::',
2020-07-28T21:24:07.141756+00:00 app[web.1]: port: 50667
2020-07-28T21:24:07.141756+00:00 app[web.1]: }
2020-07-28T21:24:07.154255+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-07-28T21:24:07.154464+00:00 app[web.1]: npm ERR! errno 1
2020-07-28T21:24:07.157313+00:00 app[web.1]: npm ERR! bot#1.0.0 start: `node bot.js`
2020-07-28T21:24:07.157445+00:00 app[web.1]: npm ERR! Exit status 1
2020-07-28T21:24:07.157646+00:00 app[web.1]: npm ERR!
2020-07-28T21:24:07.157759+00:00 app[web.1]: npm ERR! Failed at the bot#1.0.0 start script.
2020-07-28T21:24:07.157832+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-07-28T21:24:07.169750+00:00 app[web.1]:
2020-07-28T21:24:07.169882+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-07-28T21:24:07.169957+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-07-28T21_24_07_159Z-debug.log
2020-07-28T21:24:07.254000+00:00 heroku[web.1]: State changed from starting to crashed
2020-07-28T21:24:07.225012+00:00 heroku[web.1]: Process exited with status 1
package.json
{
"name": "bot",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"discord.js": "^12.2.0",
"exit-hook": "^2.2.0",
"express": "^4.17.1",
"http": "0.0.1-security",
"webpack-dev-server": "^3.11.0"
},
"scripts": {
"start": "node bot.js",
"stop-win": "Taskkill /IM node.exe /F"
},
"main": "bot.js",
"devDependencies": {},
"keywords": [],
"author": "",
"license": "ISC",
"description": ""
}
Current code (though I have tried many different ones as well.)
const express = require('express');
const path = require('path');
const PORT = process.env.PORT || 5000;
express()
.use(express.static(path.join(__dirname, 'public')))
.set('views', path.join(__dirname, 'views'))
.set('view engine', 'ejs')
.get('/', (req, res) => res.render('pages/index'))
.listen(PORT, () => console.log(`Listening on ${ PORT }`));
},);
I understand that I should probably run the bot as a Worker instead of Web through Heroku, but the option is not available to me for some reason and my Procfile was doing nothing.
I know there must be something I'm overlooking. When I run the stop-win script, it kills two node.exe processes even when I try running the code only once.
I've been looking at this for too long (days!) and keep going in circles, I need some fresh eyes and ideas. Please help!
EDIT:
Thanks Tin Nguyen for pointing me in the right direction for the Procfile! I was able to use this thread to make an echo, and thus a functioning Procfile making it a worker. This let me fix all of the mess. Thank you very much!
I think the error is comming from the port! look at the errors,
Ready!
Listening on 50667
events.js:292
throw er; // Unhandled 'error' event
Error: listen EADDRINUSE: address already in use :::50667
it says "address already in use", try to change it and let me noticied if it works!

Babel-node not found - Heroku Deploy

I am trying to deploy a simple Ecommerce website that has Reactjs , Node, Express and MongoDB. I have followed a tutorial to deploy it to the heroku. I have used babel but in the tutorial, it wasn't used. I know we don't use babel for production and used only for the development purpose, but I am not sure how I would still deploy my website.
The server is working perfectly locally and also the Heroku build is successful. But when I visit my deployed app on heroku it says application error.
Here are the logs from Heroku:
2020-06-29T16:04:44.812179+00:00 heroku[web.1]: Starting process with command `npm start`
2020-06-29T16:04:48.072669+00:00 app[web.1]:
2020-06-29T16:04:48.072690+00:00 app[web.1]: > e-commerce-site#1.0.0 start /app
2020-06-29T16:04:48.072691+00:00 app[web.1]: > babel-node backend/server.js
2020-06-29T16:04:48.072691+00:00 app[web.1]:
2020-06-29T16:04:48.105827+00:00 app[web.1]: sh: 1: babel-node: not found
2020-06-29T16:04:48.110266+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-06-29T16:04:48.111030+00:00 app[web.1]: npm ERR! syscall spawn
2020-06-29T16:04:48.111915+00:00 app[web.1]: npm ERR! file sh
2020-06-29T16:04:48.112482+00:00 app[web.1]: npm ERR! errno ENOENT
2020-06-29T16:04:48.114018+00:00 app[web.1]: npm ERR! e-commerce-site#1.0.0 start: `babel-node backend/server.js`
2020-06-29T16:04:48.114155+00:00 app[web.1]: npm ERR! spawn ENOENT
2020-06-29T16:04:48.114342+00:00 app[web.1]: npm ERR!
2020-06-29T16:04:48.114508+00:00 app[web.1]: npm ERR! Failed at the e-commerce-site#1.0.0 start script.
2020-06-29T16:04:48.114601+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-06-29T16:04:48.133545+00:00 app[web.1]:
2020-06-29T16:04:48.134148+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-06-29T16:04:48.134771+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-06-
29T16_04_48_124Z-debug.log
2020-06-29T16:04:48.213867+00:00 heroku[web.1]: Process exited with status 1
2020-06-29T16:04:48.265610+00:00 heroku[web.1]: State changed from starting to crashed
2020-06-29T16:04:48.268292+00:00 heroku[web.1]: State changed from crashed to starting
2020-06-29T16:04:57.328678+00:00 heroku[web.1]: Starting process with command `npm start`
2020-06-29T16:05:00.299582+00:00 app[web.1]:
2020-06-29T16:05:00.299595+00:00 app[web.1]: > e-commerce-site#1.0.0 start /app
2020-06-29T16:05:00.299595+00:00 app[web.1]: > babel-node backend/server.js
2020-06-29T16:05:00.299596+00:00 app[web.1]:
2020-06-29T16:05:00.308802+00:00 app[web.1]: sh: 1: babel-node: not found
2020-06-29T16:05:00.312668+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-06-29T16:05:00.313206+00:00 app[web.1]: npm ERR! syscall spawn
2020-06-29T16:05:00.313637+00:00 app[web.1]: npm ERR! file sh
2020-06-29T16:05:00.314093+00:00 app[web.1]: npm ERR! errno ENOENT
2020-06-29T16:05:00.315953+00:00 app[web.1]: npm ERR! e-commerce-site#1.0.0 start: `babel-node backend/server.js`
2020-06-29T16:05:00.316283+00:00 app[web.1]: npm ERR! spawn ENOENT
2020-06-29T16:05:00.316613+00:00 app[web.1]: npm ERR!
2020-06-29T16:05:00.316974+00:00 app[web.1]: npm ERR! Failed at the e-commerce-site#1.0.0 start script.
2020-06-29T16:05:00.317312+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-06-29T16:05:00.344371+00:00 app[web.1]:
2020-06-29T16:05:00.344828+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-06-29T16:05:00.345202+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-06-29T16_05_00_319Z-debug.log
2020-06-29T16:05:00.406294+00:00 heroku[web.1]: Process exited with status 1
2020-06-29T16:05:00.466244+00:00 heroku[web.1]: State changed from starting to crashed
File Name: Server.js
The file where I have all the connections for MongoDB:
import express from "express";
import data from "./data";
import dotenv from "dotenv";
import config from "./config";
import mongoose from "mongoose";
import userRoute from "./routes/userRoute";
import productRoute from "./routes/productRoute";
import bodyParser from "body-parser";
dotenv.config();
const mongodbUrl = config.MONGODB_URL;
const PORT = process.env.PORT || 5000;
mongoose.connect(mongodbUrl , {
useNewUrlParser : true,
useUnifiedTopology: true,
useCreateIndex: true
}).catch(error => console.log(error.reason));
const app = express();
app.use(bodyParser.json());
app.use("/api/users" , userRoute);
app.use("/api/products" , productRoute);
if (process.env.NODE_ENV === "production"){
app.use(express.static("./frontend/build"));
}
app.listen(PORT , console.log(`Server started at ${PORT}`));
File Name: config.js
export default{
MONGODB_URL: process.env.MONGODB_URL || "mongodb://localhost/ecommercesite",
JWT_SECRET: process.env.JWT_SECRET || "somethingsecret"
}
File Name: Package.json
{
"name": "e-commerce-site",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build" : "cd frontend && npm run build",
"install-client" : "cd frontend && npm install",
"heroku-postbuild" : "npm run install-client && npm run build",
"start": "babel-node backend/server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.19.2",
"body-parser": "^1.19.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.9.16"
},
"devDependencies": {
"#babel/cli": "^7.10.1",
"#babel/core": "^7.10.1",
"#babel/node": "^7.10.1",
"#babel/preset-env": "^7.10.1",
"nodemon": "^2.0.4"
}
}

Express server working locally but crashing on heroku

My Node + Express server is working locally but not on Heroku.
Also worth mentioning I'm using heroku-postgres and ran these commands
heroku run knex migrate:latest -a myAppName
heroku run knex seed:latest -a myAppName
The commands ran successfully and I can see the seeded DB on Heroku.
What's the issue?
Now when I try to access the server, it just won't work because of some modules it can't find, but again it works perfectly on my end
I'm also deploying from my development-branch, haven't yet merged to master but that shouldn't be the problem.
Heroku Logs:
2019-11-20T19:57:57.678058+00:00 heroku[web.1]: State changed from starting to crashed
2019-11-20T19:57:57.524659+00:00 app[web.1]: internal/modules/cjs/loader.js:895
2019-11-20T19:57:57.524683+00:00 app[web.1]: throw err;
2019-11-20T19:57:57.524685+00:00 app[web.1]: ^
2019-11-20T19:57:57.524686+00:00 app[web.1]:
2019-11-20T19:57:57.524689+00:00 app[web.1]: Error: Cannot find module '../../Users/Middlewares/validateUserID'
2019-11-20T19:57:57.524690+00:00 app[web.1]: Require stack:
2019-11-20T19:57:57.524692+00:00 app[web.1]: - /app/Issues/Routes/IssueRoutes.js
2019-11-20T19:57:57.524694+00:00 app[web.1]: - /app/api/server.js
2019-11-20T19:57:57.524695+00:00 app[web.1]: - /app/index.js
2019-11-20T19:57:57.524697+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:892:15)
2019-11-20T19:57:57.524698+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:785:27)
2019-11-20T19:57:57.524700+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:956:19)
2019-11-20T19:57:57.524702+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2019-11-20T19:57:57.524703+00:00 app[web.1]: at Object.<anonymous> (/app/Issues/Routes/IssueRoutes.js:6:28)
2019-11-20T19:57:57.524704+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1063:30)
2019-11-20T19:57:57.524706+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)
2019-11-20T19:57:57.524707+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:914:32)
2019-11-20T19:57:57.524708+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:822:14)
2019-11-20T19:57:57.524710+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:956:19)
2019-11-20T19:57:57.524711+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2019-11-20T19:57:57.524712+00:00 app[web.1]: at Object.<anonymous> (/app/api/server.js:10:21)
2019-11-20T19:57:57.524713+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1063:30)
2019-11-20T19:57:57.524715+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)
2019-11-20T19:57:57.524716+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:914:32)
2019-11-20T19:57:57.524717+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:822:14) {
2019-11-20T19:57:57.524718+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2019-11-20T19:57:57.524720+00:00 app[web.1]: requireStack: [
2019-11-20T19:57:57.524721+00:00 app[web.1]: '/app/Issues/Routes/IssueRoutes.js',
2019-11-20T19:57:57.524722+00:00 app[web.1]: '/app/api/server.js',
2019-11-20T19:57:57.524724+00:00 app[web.1]: '/app/index.js'
2019-11-20T19:57:57.524725+00:00 app[web.1]: ]
2019-11-20T19:57:57.524726+00:00 app[web.1]: }
2019-11-20T19:57:57.533660+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-11-20T19:57:57.534079+00:00 app[web.1]: npm ERR! errno 1
2019-11-20T19:57:57.536043+00:00 app[web.1]: npm ERR! bettercity#1.0.0 start: `node index.js`
2019-11-20T19:57:57.536045+00:00 app[web.1]: npm ERR! Exit status 1
2019-11-20T19:57:57.536154+00:00 app[web.1]: npm ERR!
2019-11-20T19:57:57.536817+00:00 app[web.1]: npm ERR! Failed at the bettercity#1.0.0 start script.
2019-11-20T19:57:57.536821+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-11-20T19:57:57.563676+00:00 app[web.1]:
2019-11-20T19:57:57.564106+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-11-20T19:57:57.564508+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-11-20T19_57_57_537Z-debug.log
2019-11-20T19:57:57.659267+00:00 heroku[web.1]: Process exited with status 1
2019-11-20T19:58:25.000000+00:00 app[api]: Build started by user myEmail#mail.com
2019-11-20T19:59:21.041005+00:00 app[api]: Deploy a1b6ff8e by user myEmail#mail.com
2019-11-20T19:59:21.041005+00:00 app[api]: Release v20 created by user myEmail#mail.com
2019-11-20T19:59:21.000000+00:00 app[api]: Build succeeded
2019-11-20T19:59:22.528003+00:00 heroku[web.1]: State changed from crashed to starting
2019-11-20T19:59:26.144682+00:00 heroku[web.1]: Starting process with command `npm start`
2019-11-20T19:59:29.286295+00:00 heroku[web.1]: State changed from starting to crashed
2019-11-20T19:59:28.777609+00:00 app[web.1]:
2019-11-20T19:59:28.777626+00:00 app[web.1]: > bettercity#1.0.0 start /app
2019-11-20T19:59:28.777628+00:00 app[web.1]: > node index.js
2019-11-20T19:59:28.777629+00:00 app[web.1]:
2019-11-20T19:59:29.268829+00:00 heroku[web.1]: Process exited with status 1
2019-11-20T19:59:29.169740+00:00 app[web.1]: internal/modules/cjs/loader.js:895
2019-11-20T19:59:29.169765+00:00 app[web.1]: throw err;
2019-11-20T19:59:29.169766+00:00 app[web.1]: ^
2019-11-20T19:59:29.169767+00:00 app[web.1]:
2019-11-20T19:59:29.169779+00:00 app[web.1]: Error: Cannot find module '../../Users/Middlewares/validateUserID'
2019-11-20T19:59:29.169780+00:00 app[web.1]: Require stack:
2019-11-20T19:59:29.169781+00:00 app[web.1]: - /app/Issues/Routes/IssueRoutes.js
2019-11-20T19:59:29.169782+00:00 app[web.1]: - /app/api/server.js
2019-11-20T19:59:29.169783+00:00 app[web.1]: - /app/index.js
2019-11-20T19:59:29.169784+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:892:15)
2019-11-20T19:59:29.169785+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:785:27)
2019-11-20T19:59:29.169786+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:956:19)
2019-11-20T19:59:29.169787+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2019-11-20T19:59:29.169788+00:00 app[web.1]: at Object.<anonymous> (/app/Issues/Routes/IssueRoutes.js:6:28)
2019-11-20T19:59:29.169789+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1063:30)
2019-11-20T19:59:29.169790+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)
2019-11-20T19:59:29.169791+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:914:32)
2019-11-20T19:59:29.169792+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:822:14)
2019-11-20T19:59:29.169793+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:956:19)
2019-11-20T19:59:29.169794+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2019-11-20T19:59:29.169795+00:00 app[web.1]: at Object.<anonymous> (/app/api/server.js:10:21)
2019-11-20T19:59:29.169796+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1063:30)
2019-11-20T19:59:29.169797+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)
2019-11-20T19:59:29.169798+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:914:32)
2019-11-20T19:59:29.169799+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:822:14) {
2019-11-20T19:59:29.169800+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2019-11-20T19:59:29.169801+00:00 app[web.1]: requireStack: [
2019-11-20T19:59:29.169802+00:00 app[web.1]: '/app/Issues/Routes/IssueRoutes.js',
2019-11-20T19:59:29.169803+00:00 app[web.1]: '/app/api/server.js',
2019-11-20T19:59:29.169804+00:00 app[web.1]: '/app/index.js'
2019-11-20T19:59:29.169805+00:00 app[web.1]: ]
2019-11-20T19:59:29.169806+00:00 app[web.1]: }
2019-11-20T19:59:29.179485+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-11-20T19:59:29.179812+00:00 app[web.1]: npm ERR! errno 1
2019-11-20T19:59:29.181606+00:00 app[web.1]: npm ERR! bettercity#1.0.0 start: `node index.js`
2019-11-20T19:59:29.181811+00:00 app[web.1]: npm ERR! Exit status 1
2019-11-20T19:59:29.182146+00:00 app[web.1]: npm ERR!
2019-11-20T19:59:29.182403+00:00 app[web.1]: npm ERR! Failed at the bettercity#1.0.0 start script.
2019-11-20T19:59:29.182699+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-11-20T19:59:29.198787+00:00 app[web.1]:
2019-11-20T19:59:29.199117+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-11-20T19:59:29.199119+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-11-20T19_59_29_183Z-debug.log
package.json
{
"name": "bettercity",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"server": "nodemon index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/rodpa715/bettercity.git"
},
"author": "Patrick Rodrigues",
"license": "ISC",
"bugs": {
"url": "https://github.com/rodpa715/bettercity/issues"
},
"homepage": "https://github.com/rodpa715/bettercity#readme",
"dependencies": {
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"helmet": "^3.21.2",
"jsonwebtoken": "^8.5.1",
"knex": "^0.20.2",
"node": "^13.1.0",
"pg": "^7.12.1"
},
"engines": {
"node": "^10.16.3",
"npm": "6.13.0"
},
"devDependencies": {
"jest": "^24.9.0",
"nodemon": "^1.19.4",
"supertest": "^4.0.2"
}
}
[SOLVED]
It seems as though GitHub doesn't track folder case-sensitivity change so even when I renamed the folders it didn't work. I copied everything into a new repo and it deployed successfully.
Try changing
const { validateUserID } = require("../../Users/Middlewares/validateUserID");
to
const { validateUserID } = require("../../users/Middlewares/validateUserID");
with a lowercase users
linux is case sensitive and it might be giving issues on a server but not on your machine if you have a mac.
Your paths to the routes are incorrect and node cannot find those in the Heroku filesystem.
Work off your current file using like './' so you update to:
const authRoutes = require("./../Authentication/Routes/AuthRoutes");

Resources