is there a way to solve heroku 503 deploying error? - node.js

I would like to thank you guys in advance. so I am having issues opening my express server after I have deployed it on Heroku. The issue is I keep on getting the error below and I hope someone can please help me.
2023-02-06T09:34:31.419072+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2023-02-06T09:34:31.419234+00:00 app[web.1]: npm ERR! errno 1
2023-02-06T09:34:31.419978+00:00 app[web.1]: npm ERR! server#1.0.0 start: node server.js
2023-02-06T09:34:31.420062+00:00 app[web.1]: npm ERR! Exit status 1
2023-02-06T09:34:31.420152+00:00 app[web.1]: npm ERR!
2023-02-06T09:34:31.420229+00:00 app[web.1]: npm ERR! Failed at the server#1.0.0 start script.
2023-02-06T09:34:31.420301+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2023-02-06T09:34:31.428635+00:00 app[web.1]:
2023-02-06T09:34:31.428714+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2023-02-06T09:34:31.428770+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2023-02-06T09_34_31_420Z-debug.log
2023-02-06T09:34:31.607388+00:00 heroku[web.1]: Process exited with status 1
2023-02-06T09:34:31.670514+00:00 heroku[web.1]: State changed from starting to crashed
2023-02-06T09:34:57.360088+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=thewrightlogistic.herokuapp.com request_id=45a256da-ca0f-4af1-86a6-a7fc81112803 fwd="98.174.153.51" dyno= connect= service= status=503 bytes= protocol=https
2023-02-06T09:34:57.360088+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=thewrightlogistic.herokuapp.com request_id=45a256da-ca0f-4af1-86a6-a7fc81112803 fwd="98.174.153.51" dyno= connect= service= status=503 bytes= protocol=https
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser')
const mongoose = require('./database')
const middleware = require('./middleware')
const cors = require('cors')
const app = express();
const contactRouter = require('./routes/contactRoutes');
const authRouter = require('./routes/authRoutes');
const userRouter = require('./routes/userRoutes');
// const dashboardRouter = require('./routes/dashboard');
// view engine setup
app.set('view engine', 'ejs' );
// STATIC FILES
app.use(express.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static('public'));
app.use(cors())
// post contact route
app.use('/auth',authRouter );
app.use('/users',userRouter );
app.use('/contact',contactRouter );
// app.use('/dashboard',dashboardRouter );
// FOR PRODUCTION
app.listen(process.env.PORT || 8080, () => {
console.log(`Listening on port 8080`)
})

Related

My app deployed successfully in Heroku but in times of opening the app show error

My app successfully deployed to Heroku..
****: Deployed 6bc02eb8 Today at 4:19 PM · v23 ·
Compare diff **** ****: Build
succeeded Today at 4:18 PM · View build log
But It shows error when try to open my app...
2022-06-29T10:19:45.228279+00:00 app[web.1]: npm ERR!
2022-06-29T10:19:45.228377+00:00 app[web.1]: npm ERR! Failed at the
blog-application#1.0.0 start script. 2022-06-29T10:19:45.228470+00:00
app[web.1]: npm ERR! This is probably not a problem with npm. There is
likely additional logging output above.
2022-06-29T10:19:45.236802+00:00 app[web.1]:
2022-06-29T10:19:45.237020+00:00 app[web.1]: npm ERR! A complete log
of this run can be found in: 2022-06-29T10:19:45.237112+00:00
app[web.1]: npm ERR!
/app/.npm/_logs/2022-06-29T10_19_45_229Z-debug.log
2022-06-29T10:19:45.431649+00:00 heroku[web.1]: Process exited with
status 1 2022-06-29T10:19:45.541882+00:00 heroku[web.1]: State changed
from starting to crashed 2022-06-29T10:19:48.705353+00:00
heroku[router]: at=error code=H10 desc="App crashed" method=GET
path="/" host=syt-share-your-thoughts.herokuapp.com
request_id=0bb2aaff-6bce-41fb-891e-d3b361a122f8 fwd="59.153.103.22"
dyno= connect= service= status=503 bytes= protocol=https
2022-06-29T10:19:51.151462+00:00 heroku[router]: at=error code=H10
desc="App crashed" method=GET path="/favicon.ico"
host=syt-share-your-thoughts.herokuapp.com
request_id=c0d24108-01a7-44b7-96dd-e8cc62bcaa7c fwd="59.153.103.22"
dyno= connect= service= status=503 bytes= protocol=https
here is my package.json file:
{
"name": "blog-application",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node app.js",
"dev": "nodemon app.js"
},
"author": "Md Shareful Islam",
"license": "ISC",
"dependencies": {
"bcrypt": "^5.0.1",
"chalk": "^4.1.0",
"cheerio": "^1.0.0-rc.11",
"config": "^3.3.7",
"connect-flash": "^0.1.1",
"connect-mongodb-session": "^3.1.1",
"debug": "^4.3.4",
"dotenv": "^16.0.1",
"ejs": "^3.1.8",
"express": "^4.18.1",
"express-session": "^1.17.3",
"express-validator": "^6.14.1",
"moment": "^2.29.3",
"mongoose": "^6.3.8",
"morgan": "^1.10.0",
"multer": "^1.4.5-lts.1",
"nodemon": "^2.0.16",
"reading-time": "^1.5.0",
"validator": "^13.7.0"
},
"engines": {
"node": "14.15.5"
}
}
And this is my main file:
require('dotenv').config()
const express = require('express');
const mongoose = require('mongoose')
const config = require('config')
const chalk = require('chalk')
// import middleware
const setMiddleware = require('./middleware/middleware')
//Import Routes
const setRoutes = require('./routes/routes')
const MONGODB_URI = `mongodb+srv://${config.get('db-admin')}:${config.get('db-password')}#blogapp.ool50gr.mongodb.net/?retryWrites=true&w=majority`
const app = express();
// Setup View Engine
app.set('view engine', 'ejs')
app.set('views', 'views')
// Using Middleware from Middleware Directory
setMiddleware(app)
// Using Routes from Route Directory
setRoutes(app)
// ** middleware to handle 404 and 500.
app.use((req, res, next) => {
let error = new Error('404 Page Not Found');
error.status = 404;
next(error);
})
app.use((error, req, res, next) => {
if(error.status === 404) {
return res.render('pages/error/404', {flashMessage: {}})
}
res.render('pages/error/500', {flashMessage: {}})
})
const PORT = process.env.PORT || 8080;
mongoose.connect(MONGODB_URI,
{useNewUrlParser: true})
.then(() => {
console.log(chalk.green.bold('Database connected!'))
app.listen(PORT, () => {
console.log(chalk.green.italic(`App is running on PORT ${PORT}`));
});
})
.catch(e => {
return console.log(e)
})
Here are logs datails from Heroku...
2022-06-29T16:18:56.404997+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2022-06-29T16:18:56.405076+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2022-06-29T16_18_56_398Z-debug.log
2022-06-29T16:18:56.554135+00:00 heroku[web.1]: Process exited with status 1
2022-06-29T16:18:56.637092+00:00 heroku[web.1]: State changed from starting to crashed
2022-06-29T16:18:56.640222+00:00 heroku[web.1]: State changed from crashed to starting
2022-06-29T16:19:00.220649+00:00 heroku[web.1]: Starting process with command `npm start`
2022-06-29T16:19:03.473783+00:00 app[web.1]:
2022-06-29T16:19:03.473792+00:00 app[web.1]: > blog-application#1.0.0 start /app
2022-06-29T16:19:03.473792+00:00 app[web.1]: > node app.js
2022-06-29T16:19:03.473792+00:00 app[web.1]:
2022-06-29T16:19:35.090006+00:00 app[web.1]: /app/node_modules/mongodb/lib/utils.js:417
2022-06-29T16:19:35.090017+00:00 app[web.1]: throw error;
2022-06-29T16:19:35.090018+00:00 app[web.1]: ^
2022-06-29T16:19:35.090019+00:00 app[web.1]:
2022-06-29T16:19:35.090020+00:00 app[web.1]: Error: Error connecting to db: connection <monitor> to 13.250.175.230:27017 closed
2022-06-29T16:19:35.090021+00:00 app[web.1]: at /app/node_modules/connect-mongodb-session/index.js:88:17
2022-06-29T16:19:35.090021+00:00 app[web.1]: at /app/node_modules/mongodb/lib/utils.js:413:17
2022-06-29T16:19:35.090022+00:00 app[web.1]: at /app/node_modules/mongodb/lib/mongo_client.js:129:28
2022-06-29T16:19:35.090022+00:00 app[web.1]: at connectCallback (/app/node_modules/mongodb/lib/operations/connect.js:29:9)
2022-06-29T16:19:35.090023+00:00 app[web.1]: at /app/node_modules/mongodb/lib/operations/connect.js:78:20
2022-06-29T16:19:35.090023+00:00 app[web.1]: at Object.callback (/app/node_modules/mongodb/lib/sdam/topology.js:208:50)
2022-06-29T16:19:35.090024+00:00 app[web.1]: at Timeout._onTimeout (/app/node_modules/mongodb/lib/sdam/topology.js:319:33)
2022-06-29T16:19:35.090024+00:00 app[web.1]: at listOnTimeout (internal/timers.js:554:17)
2022-06-29T16:19:35.090024+00:00 app[web.1]: at processTimers (internal/timers.js:497:7)
2022-06-29T16:19:35.109275+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2022-06-29T16:19:35.109568+00:00 app[web.1]: npm ERR! errno 1
2022-06-29T16:19:35.113501+00:00 app[web.1]: npm ERR! blog-application#1.0.0 start: `node app.js`
2022-06-29T16:19:35.113599+00:00 app[web.1]: npm ERR! Exit status 1
2022-06-29T16:19:35.113705+00:00 app[web.1]: npm ERR!
2022-06-29T16:19:35.113792+00:00 app[web.1]: npm ERR! Failed at the blog-application#1.0.0 start script.
2022-06-29T16:19:35.113876+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2022-06-29T16:19:35.120692+00:00 app[web.1]:
2022-06-29T16:19:35.120808+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2022-06-29T16:19:35.120859+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2022-06-29T16_19_35_114Z-debug.log
2022-06-29T16:19:35.785417+00:00 heroku[web.1]: State changed from starting to crashed
2022-06-29T16:19:35.273101+00:00 heroku[web.1]: Process exited with status 1
2022-06-29T16:19:38.894464+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=syt-share-your-thoughts.herokuapp.com request_id=2b13bcd5-e764-4e60-a254-394a8b0f7531 fwd="59.153.103.22" dyno= connect= service= status=503 bytes= protocol=https
2022-06-29T16:19:41.185482+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=syt-share-your-thoughts.herokuapp.com request_id=6109b89a-818d-4827-804b-98c1a875a3ab fwd="59.153.103.22" dyno= connect= service= status=503 bytes= protocol=https
you don't provide enought information for us to be able to help you, nobody can or will debug it for you in that regard.
Here, sharing your package.json and the entry file of your application would be useful!
Anyway it seems that npm run start is crashing, you could start by making sure that whatever command is run by npm run start is accessible in heroku (You might use a global dependencies that you have installed on your local machine which heroku doesn't).
I'll be glad to help you more if you provide required code snippets for us to understand what's happening!

NodeJS app deployed on heroku issue - not retrieving data from database

I'm having an issue with my full-stack application, (MySQL-Express-React-NodeJS). I have deployed it to Heroku everything is working except the pages that are connected to get or post to ClearDB MySQL database! Any advises or hints on something that I might have forgot to do? I'm also using the ClearDB add-on from Heroku if that helps.
server.js:
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const app = express();
const http = require("http");
const server = http.createServer(app);
const connection = require("./app/Models/database");
// require user the route
const user = require("./app/routes/user");
// require the doctor route
const doctor = require("./app/routes/doctor");
// require the question route
const questions = require("./app/routes/questions.js");
// require the schedule route
const schedule = require("./app/routes/schedule");
const appointement = require("./app/routes/appointment");
const socket = require("socket.io");
const io = socket(server);
app.use(cors());
// set the port
const port = process.env.PORT || 5000;
// parse requests of content-type - application/json
app.use(bodyParser.json());
// parse requests of content-type - application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }));
// define the user router
app.use("/users", user);
app.use("/doctor", doctor);
app.use("/questions", questions);
app.use("/schedule", schedule);
app.use("/appointment", appointement);
app.use(function (error, req, res, next) {
if (error instanceof SyntaxError) {
//Handle SyntaxError here.
return res.status(500).send({ data: "Invalid data" });
} else {
next();
}
});
const peers = {};
io.on("connection", (socket) => {
//
if (!peers[socket.id]) {
peers[socket.id] = socket.id;
}
socket.emit("yourID", socket.id); // allows you to emit custom events on the server and client
io.sockets.emit("allUsers", peers); //will send to all the clients ......socket.broadcast.emit will send the message to all the other clients except the newly created connection
socket.on("disconnect", () => {
delete peers[socket.id]; //after the user leave the room
});
socket.on("callUser", (data) => {
io.to(data.userToCall).emit("hello", {
signal: data.signalData,
from: data.from,
}); //io.to('some room').emit('some event');
});
socket.on("acceptCall", (data) => {
io.to(data.to).emit("callAccepted", data.signal);
});
});
//test route
app.get("/test", function (req, res) {
res.send( "test");
});
app.listen(port, () => {
console.log(`Server is Running on port ${port}`);
});
Heroku logs:
2021-01-04T18:46:17.729977+00:00 heroku[web.1]: Restarting
2021-01-04T18:46:17.732430+00:00 heroku[web.1]: State changed from up to starting
2021-01-04T18:46:18.729190+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2021-01-04T18:46:18.801647+00:00 heroku[web.1]: Process exited with status 143
2021-01-04T18:46:53.555253+00:00 heroku[web.1]: Starting process with command `npm start`
2021-01-04T18:46:57.234794+00:00 app[web.1]:
2021-01-04T18:46:57.234819+00:00 app[web.1]: > server#1.0.0 start
2021-01-04T18:46:57.234819+00:00 app[web.1]: > node server.js
2021-01-04T18:46:57.234820+00:00 app[web.1]:
2021-01-04T18:46:58.471423+00:00 app[web.1]: /app/server.js:61
2021-01-04T18:46:58.471444+00:00 app[web.1]: console.log(`Server is Running in port:${port}`);
2021-01-04T18:46:58.471446+00:00 app[web.1]: ^
2021-01-04T18:46:58.471446+00:00 app[web.1]:
2021-01-04T18:46:58.471447+00:00 app[web.1]: ReferenceError: port is not defined
2021-01-04T18:46:58.471447+00:00 app[web.1]: at Server.<anonymous> (/app/server.js:61:44)
2021-01-04T18:46:58.471447+00:00 app[web.1]: at Object.onceWrapper (node:events:482:28)
2021-01-04T18:46:58.471448+00:00 app[web.1]: at Server.emit (node:events:388:22)
2021-01-04T18:46:58.471448+00:00 app[web.1]: at emitListeningNT (node:net:1329:10)
2021-01-04T18:46:58.471449+00:00 app[web.1]: at processTicksAndRejections (node:internal/process/task_queues:79:21)
2021-01-04T18:46:58.502509+00:00 app[web.1]: npm ERR! code 1
2021-01-04T18:46:58.503140+00:00 app[web.1]: npm ERR! path /app
2021-01-04T18:46:58.509321+00:00 app[web.1]: npm ERR! command failed
2021-01-04T18:46:58.509747+00:00 app[web.1]: npm ERR! command sh -c node server.js
2021-01-04T18:46:58.536286+00:00 app[web.1]:
2021-01-04T18:46:58.542292+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-01-04T18:46:58.542507+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-01-04T18_46_58_510Z-debug.log
2021-01-04T18:46:58.614100+00:00 heroku[web.1]: Process exited with status 1
2021-01-04T18:46:58.673495+00:00 heroku[web.1]: State changed from starting to crashed
2021-01-04T18:46:58.677305+00:00 heroku[web.1]: State changed from crashed to starting
2021-01-04T18:47:24.050526+00:00 heroku[web.1]: Starting process with command `npm start`
2021-01-04T18:47:27.323089+00:00 app[web.1]:
2021-01-04T18:47:27.323103+00:00 app[web.1]: > server#1.0.0 start
2021-01-04T18:47:27.323103+00:00 app[web.1]: > node server.js
2021-01-04T18:47:27.323104+00:00 app[web.1]:
2021-01-04T18:47:27.950882+00:00 app[web.1]: /app/server.js:61
2021-01-04T18:47:27.950900+00:00 app[web.1]: console.log(`Server is Running in port:${port}`);
2021-01-04T18:47:27.950901+00:00 app[web.1]: ^
2021-01-04T18:47:27.950903+00:00 app[web.1]:
2021-01-04T18:47:27.950903+00:00 app[web.1]: ReferenceError: port is not defined
2021-01-04T18:47:27.950903+00:00 app[web.1]: at Server.<anonymous> (/app/server.js:61:44)
2021-01-04T18:47:27.950904+00:00 app[web.1]: at Object.onceWrapper (node:events:482:28)
2021-01-04T18:47:27.950904+00:00 app[web.1]: at Server.emit (node:events:388:22)
2021-01-04T18:47:27.950904+00:00 app[web.1]: at emitListeningNT (node:net:1329:10)
2021-01-04T18:47:27.950905+00:00 app[web.1]: at processTicksAndRejections (node:internal/process/task_queues:79:21)
2021-01-04T18:47:27.970852+00:00 app[web.1]: npm ERR! code 1
2021-01-04T18:47:27.971425+00:00 app[web.1]: npm ERR! path /app
2021-01-04T18:47:27.976210+00:00 app[web.1]: npm ERR! command failed
2021-01-04T18:47:27.976596+00:00 app[web.1]: npm ERR! command sh -c node server.js
2021-01-04T18:47:27.987341+00:00 app[web.1]:
2021-01-04T18:47:27.987620+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-01-04T18:47:27.987792+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-01-04T18_47_27_977Z-debug.log
2021-01-04T18:47:28.067423+00:00 heroku[web.1]: Process exited with status 1
2021-01-04T18:47:28.111585+00:00 heroku[web.1]: State changed from starting to crashed
2021-01-04T18:48:09.000000+00:00 app[api]: Build started by user ishaqatfarah#gmail.com
2021-01-04T18:50:08.503349+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=speakout-2.herokuapp.com request_id=41eadebc-6547-4735-975c-47f07af41139 fwd="46.185.242.147" dyno= connect= service= status=503 bytes= protocol=https
2021-01-04T18:50:13.899678+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=speakout-2.herokuapp.com request_id=f9c641f9-30c1-4ef7-a184-0d286cecf4c0 fwd="46.185.242.147" dyno= connect= service= status=503 bytes= protocol=https
2021-01-04T18:50:37.722683+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=speakout-2.herokuapp.com request_id=a897151b-2c68-440d-bb39-877ad0e80b3c fwd="46.185.242.147" dyno= connect= service= status=503 bytes= protocol=https
2021-01-04T18:50:38.328012+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=speakout-2.herokuapp.com request_id=3b546e46-3812-4a18-8f78-f585c9f3e740 fwd="46.185.242.147" dyno= connect= service= status=503 bytes= protocol=https
2021-01-04T18:50:44.226260+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=speakout-2.herokuapp.com request_id=df1690f0-5e59-4105-aae7-857d2a2ef8ff fwd="46.185.242.147" dyno= connect= service= status=503 bytes= protocol=https
2021-01-04T18:50:44.682096+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=speakout-2.herokuapp.com request_id=d4bee131-4929-4f80-96dd-d829a6c53bde fwd="46.185.242.147" dyno= connect= service= status=503 bytes= protocol=https

Mern app working locally - 503 error on Heroku (H10-H13)

I have made a project through a course with Brad Traversy called contact keeper. It works fine locally on my machine and I get contact with the database.
Once I push it to Heroku I cant log in or register anymore. I get a 503 error (H10 & H13 errors from heroku) saying service unavailable when trying to hit those endpoints.
I have tried looking on similar threads but it does not work for me. I have added a procfile and checked through my package.json and it looks alright (from what I see).
The full repository can be found here: https://github.com/Dannus90/Contact_Keeper_MERN
const express = require('express');
const connectDB = require('./config/db');
const path = require('path');
const app = express();
// Connect Database
connectDB();
// Init Middleware
app.use(express.json({ extended: false }));
// Define Routes
app.use('/api/users', require('./routes/users'));
app.use('/api/auth', require('./routes/auth'));
app.use('/api/contacts', require('./routes/contacts'));
// Serve static assets in production
if (process.env.NODE_ENV === 'production') {
// Set static folder
app.use(express.static('client/build'));
app.get('*', (req, res) =>
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
);
}
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server started on port ${PORT}`));
In the picture below you can see where it fails. It is in the AuthState file when it tries to hit the endpoints.
The complete error log from heroku can be seen below:
2020-05-17T09:23:20.616623+00:00 heroku[web.1]: State changed from starting to up
2020-05-17T09:23:50.230066+00:00 app[web.1]: connection <monitor> to 52.31.65.44:27017 closed
2020-05-17T09:23:50.240114+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-05-17T09:23:50.240313+00:00 app[web.1]: npm ERR! errno 1
2020-05-17T09:23:50.241253+00:00 app[web.1]: npm ERR! contact-keeper#1.0.0 start: `node server.js`
2020-05-17T09:23:50.241374+00:00 app[web.1]: npm ERR! Exit status 1
2020-05-17T09:23:50.241498+00:00 app[web.1]: npm ERR!
2020-05-17T09:23:50.241622+00:00 app[web.1]: npm ERR! Failed at the contact-keeper#1.0.0 start script.
2020-05-17T09:23:50.241760+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-05-17T09:23:50.249534+00:00 app[web.1]:
2020-05-17T09:23:50.249723+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-05-17T09:23:50.249843+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-05-17T09_23_50_242Z-debug.log
2020-05-17T09:23:50.311445+00:00 heroku[web.1]: State changed from up to crashed
2020-05-17T09:26:49.000000+00:00 app[api]: Build started by user persson.daniel.1990#gmail.com
2020-05-17T09:28:20.734327+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-17T09:28:20.461350+00:00 app[api]: Release v48 created by user persson.daniel.1990#gmail.com
2020-05-17T09:28:20.461350+00:00 app[api]: Deploy 502ce232 by user persson.daniel.1990#gmail.com
2020-05-17T09:28:21.000000+00:00 app[api]: Build succeeded
2020-05-17T09:28:30.543747+00:00 app[web.1]:
2020-05-17T09:28:30.543761+00:00 app[web.1]: > contact-keeper#1.0.0 start /app
2020-05-17T09:28:30.543761+00:00 app[web.1]: > node server.js
2020-05-17T09:28:30.543762+00:00 app[web.1]:
2020-05-17T09:28:31.157953+00:00 app[web.1]: Server started on port 13966
2020-05-17T09:28:32.044290+00:00 heroku[web.1]: State changed from starting to up
2020-05-17T09:28:33.217189+00:00 heroku[router]: at=info method=GET path="/" host=afternoon-earth-34040.herokuapp.com request_id=ed1492f5-d053-4ecf-8a88-8561992f3403 fwd="78.82.2.105" dyno=web.1 connect=0ms service=11ms status=200 bytes=2626 protocol=https
2020-05-17T09:28:33.348570+00:00 heroku[router]: at=info method=GET path="/static/css/main.abec718a.chunk.css" host=afternoon-earth-34040.herokuapp.com request_id=410da44d-797f-4a41-bafe-f130118e8c6d fwd="78.82.2.105" dyno=web.1 connect=0ms service=4ms status=200 bytes=4578 protocol=https
2020-05-17T09:28:33.346039+00:00 heroku[router]: at=info method=GET path="/static/js/main.6e77bd50.chunk.js" host=afternoon-earth-34040.herokuapp.com request_id=018e556e-91d6-4944-bd6e-0c5b74ece68a fwd="78.82.2.105" dyno=web.1 connect=0ms service=4ms status=200 bytes=28978 protocol=https
2020-05-17T09:28:33.474881+00:00 heroku[router]: at=info method=GET path="/static/js/2.9c49eab7.chunk.js" host=afternoon-earth-34040.herokuapp.com request_id=5379490e-fd9b-47c1-b001-15e036784e2d fwd="78.82.2.105" dyno=web.1 connect=0ms service=10ms status=200 bytes=192222 protocol=https
2020-05-17T09:28:33.992494+00:00 heroku[router]: at=info method=GET path="/api/contacts" host=afternoon-earth-34040.herokuapp.com request_id=3684bbba-83b1-4d90-b9f8-d4ba7dedbc60 fwd="78.82.2.105" dyno=web.1 connect=0ms service=2ms status=401 bytes=257 protocol=https
2020-05-17T09:28:33.990977+00:00 heroku[router]: at=info method=GET path="/api/auth" host=afternoon-earth-34040.herokuapp.com request_id=705c0086-3927-4e6f-b2dd-45ac9165e303 fwd="78.82.2.105" dyno=web.1 connect=0ms service=4ms status=401 bytes=257 protocol=https
2020-05-17T09:28:34.365542+00:00 heroku[router]: at=info method=GET path="/manifest.json" host=afternoon-earth-34040.herokuapp.com request_id=1f38b786-2c3d-411e-8aee-6862c40e77d4 fwd="78.82.2.105" dyno=web.1 connect=1ms service=6ms status=200 bytes=787 protocol=https
2020-05-17T09:28:34.483877+00:00 heroku[router]: at=info method=GET path="/logo192.png" host=afternoon-earth-34040.herokuapp.com request_id=65807958-8954-4332-8cab-dc4320e2cac8 fwd="78.82.2.105" dyno=web.1 connect=0ms service=2ms status=200 bytes=5622 protocol=https
2020-05-17T09:28:42.084546+00:00 heroku[router]: at=info method=GET path="/static/js/2.9c49eab7.chunk.js.map" host=afternoon-earth-34040.herokuapp.com request_id=d186f408-b227-4ce3-8f6d-2858c2b6b5a0 fwd="78.82.2.105" dyno=web.1 connect=0ms service=18ms status=200 bytes=624338 protocol=https
2020-05-17T09:28:42.056584+00:00 heroku[router]: at=info method=GET path="/static/css/main.abec718a.chunk.css" host=afternoon-earth-34040.herokuapp.com request_id=4ebde32e-fca4-4968-89d2-e10af56e5ad3 fwd="78.82.2.105" dyno=web.1 connect=0ms service=4ms status=304 bytes=238 protocol=https
2020-05-17T09:28:42.176331+00:00 heroku[router]: at=info method=GET path="/static/js/main.6e77bd50.chunk.js.map" host=afternoon-earth-34040.herokuapp.com request_id=22d537d1-9c6e-445b-985a-78f2319dd192 fwd="78.82.2.105" dyno=web.1 connect=0ms service=4ms status=200 bytes=61221 protocol=https
2020-05-17T09:28:42.289347+00:00 heroku[router]: at=info method=GET path="/static/css/main.abec718a.chunk.css.map" host=afternoon-earth-34040.herokuapp.com request_id=7418f08d-9c43-47e0-b2d3-2f2d23652356 fwd="78.82.2.105" dyno=web.1 connect=0ms service=2ms status=200 bytes=15892 protocol=https
2020-05-17T09:29:01.254923+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/api/auth" host=afternoon-earth-34040.herokuapp.com request_id=82f5a82c-e065-4e9e-a284-a82ba86287d2 fwd="78.82.2.105" dyno=web.1 connect=0ms service=15877ms status=503 bytes=0 protocol=https
2020-05-17T09:29:01.362981+00:00 heroku[web.1]: State changed from up to crashed
2020-05-17T09:29:01.235846+00:00 app[web.1]: connection <monitor> to 54.72.107.147:27017 closed
2020-05-17T09:29:01.262738+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-05-17T09:29:01.263049+00:00 app[web.1]: npm ERR! errno 1
2020-05-17T09:29:01.263998+00:00 app[web.1]: npm ERR! contact-keeper#1.0.0 start: `node server.js`
2020-05-17T09:29:01.264159+00:00 app[web.1]: npm ERR! Exit status 1
2020-05-17T09:29:01.264337+00:00 app[web.1]: npm ERR!
2020-05-17T09:29:01.264484+00:00 app[web.1]: npm ERR! Failed at the contact-keeper#1.0.0 start script.
2020-05-17T09:29:01.264618+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-05-17T09:29:01.270789+00:00 app[web.1]:
2020-05-17T09:29:01.270997+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-05-17T09:29:01.271145+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-05-17T09_29_01_265Z-debug.log
2020-05-17T09:29:01.256625+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/api/auth" host=afternoon-earth-34040.herokuapp.com request_id=0e0e84a4-257b-43bd-a31d-b97ebaed5a10 fwd="78.82.2.105" dyno=web.1 connect=0ms service=16031ms status=503 bytes=0 protocol=https
2020-05-17T09:29:01.256627+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/api/auth" host=afternoon-earth-34040.herokuapp.com request_id=acbb4fdf-bf07-4668-886e-a253a3e0aee3 fwd="78.82.2.105" dyno=web.1 connect=0ms service=15442ms status=503 bytes=0 protocol=https
2020-05-17T09:29:01.257557+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/api/auth" host=afternoon-earth-34040.herokuapp.com request_id=1a45a04e-0c1e-47ea-b796-7299db72f732 fwd="78.82.2.105" dyno=web.1 connect=0ms service=21480ms status=503 bytes=0 protocol=https
2020-05-17T09:29:01.257996+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/api/auth" host=afternoon-earth-34040.herokuapp.com request_id=2531aa80-5bf8-42e8-b620-ff9f2969ba1f fwd="78.82.2.105" dyno=web.1 connect=0ms service=15579ms status=503 bytes=0 protocol=https
2020-05-17T09:29:04.000000+00:00 app[api]: Build started by user persson.daniel.1990#gmail.com
2020-05-17T09:30:32.857023+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-17T09:30:32.560586+00:00 app[api]: Release v49 created by user persson.daniel.1990#gmail.com
2020-05-17T09:30:32.560586+00:00 app[api]: Deploy aba0d37e by user persson.daniel.1990#gmail.com
2020-05-17T09:30:34.000000+00:00 app[api]: Build succeeded
2020-05-17T09:30:44.786119+00:00 app[web.1]:
2020-05-17T09:30:44.786136+00:00 app[web.1]: > contact-keeper#1.0.0 start /app
2020-05-17T09:30:44.786137+00:00 app[web.1]: > node server.js
2020-05-17T09:30:44.786137+00:00 app[web.1]:
2020-05-17T09:30:45.574040+00:00 app[web.1]: Server started on port 52681
2020-05-17T09:30:46.081535+00:00 heroku[web.1]: State changed from starting to up
2020-05-17T09:31:15.677435+00:00 app[web.1]: connection <monitor> to 52.31.65.44:27017 closed
2020-05-17T09:31:15.698356+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-05-17T09:31:15.698666+00:00 app[web.1]: npm ERR! errno 1
2020-05-17T09:31:15.699733+00:00 app[web.1]: npm ERR! contact-keeper#1.0.0 start: `node server.js`
2020-05-17T09:31:15.699922+00:00 app[web.1]: npm ERR! Exit status 1
2020-05-17T09:31:15.700135+00:00 app[web.1]: npm ERR!
2020-05-17T09:31:15.700312+00:00 app[web.1]: npm ERR! Failed at the contact-keeper#1.0.0 start script.
2020-05-17T09:31:15.700467+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-05-17T09:31:15.723946+00:00 app[web.1]:
2020-05-17T09:31:15.724237+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-05-17T09:31:15.724392+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-05-17T09_31_15_704Z-debug.log
2020-05-17T09:31:15.828237+00:00 heroku[web.1]: State changed from up to crashed
2020-05-17T09:35:10.524783+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-17T09:35:21.345206+00:00 app[web.1]:
2020-05-17T09:35:21.345238+00:00 app[web.1]: > contact-keeper#1.0.0 start /app
2020-05-17T09:35:21.345238+00:00 app[web.1]: > node server.js
2020-05-17T09:35:21.345239+00:00 app[web.1]:
2020-05-17T09:35:22.181653+00:00 app[web.1]: Server started on port 57715
2020-05-17T09:35:22.526258+00:00 heroku[web.1]: State changed from starting to up
2020-05-17T09:35:52.241989+00:00 app[web.1]: connection <monitor> to 54.72.107.147:27017 closed
2020-05-17T09:35:52.255501+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-05-17T09:35:52.256048+00:00 app[web.1]: npm ERR! errno 1
2020-05-17T09:35:52.257707+00:00 app[web.1]: npm ERR! contact-keeper#1.0.0 start: `node server.js`
2020-05-17T09:35:52.258009+00:00 app[web.1]: npm ERR! Exit status 1
2020-05-17T09:35:52.258313+00:00 app[web.1]: npm ERR!
2020-05-17T09:35:52.258505+00:00 app[web.1]: npm ERR! Failed at the contact-keeper#1.0.0 start script.
2020-05-17T09:35:52.258686+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-05-17T09:35:52.266384+00:00 app[web.1]:
2020-05-17T09:35:52.266689+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-05-17T09:35:52.266864+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-05-17T09_35_52_259Z-debug.log
2020-05-17T09:35:52.425747+00:00 heroku[web.1]: State changed from up to crashed
2020-05-17T09:37:40.075229+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=afternoon-earth-34040.herokuapp.com request_id=b86ff65a-3c2f-4609-85ba-a75500f93e3a fwd="78.82.2.105" dyno= connect= service= status=503 bytes= protocol=https
2020-05-17T09:37:40.189972+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=afternoon-earth-34040.herokuapp.com request_id=d5b50b56-a5df-4d19-9c0f-6298c0dea421 fwd="78.82.2.105" dyno= connect= service= status=503 bytes= protocol=https
2020-05-17T09:37:42.254860+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/login" host=afternoon-earth-34040.herokuapp.com request_id=20cdf3b9-5883-4dcd-898a-03eb6ee20dc5 fwd="78.82.2.105" dyno= connect= service= status=503 bytes= protocol=https
2020-05-17T09:37:43.970046+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/login" host=afternoon-earth-34040.herokuapp.com request_id=dc0e7da8-46fa-4da1-bdb6-4814157e43a5 fwd="78.82.2.105" dyno= connect= service= status=503 bytes= protocol=https
2020-05-17T09:37:44.242232+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=afternoon-earth-34040.herokuapp.com request_id=53adb339-25bb-4bca-9b89-638035820973 fwd="78.82.2.105" dyno= connect= service= status=503 bytes= protocol=https
This is the code from my db file:
const mongoose = require("mongoose");
const config = require("config");
const db = config.get("mongoURI");
const connectDB = async () => {
try {
await mongoose.connect(db, {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
});
console.log("MongoDB Connected");
} catch (err) {
console.error(err.message);
process.exit(1);
}
};
module.exports = connectDB;
This is the database (found in default and production.js):
{
"mongoURI": "mongodb+srv://Daniel123:Daniel123#contactkeeper-rjjr4.mongodb.net/test?retryWrites=true&w=majority",
"jwtSecret": "secret"
}
Solution for me for this problem (incase anyone else get the problem):
I whitelisted 0.0.0.0/0 on mongodb, set environmental variables on heroku and set them as an alternative for the db connect(same with jwtSecret in the config), since the config was ignored when pushing to heroku:
const mongoose = require("mongoose");
const config = require("config");
const db = config.get("mongoURI");
const connectDB = async () => {
try {
await mongoose.connect(db || process.env.mongoURI, {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
});
console.log("MongoDB Connected");
} catch (err) {
console.error(err.message);
process.exit(1);
}
};
module.exports = connectDB;

Error deploying MERN application to Heroku

The app successfully deploys but when I try to open the app, I get the following error:
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. You can do this from the Heroku CLI with the command
heroku logs --tail
I ran -heroku logs --tail and I get the following:
deons-mbp:shrinkURL deonchoi$ heroku logs --tail
2019-12-13T02:59:25.356685+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-12-13T02:59:25.356952+00:00 app[web.1]: npm ERR! errno 1
2019-12-13T02:59:25.357905+00:00 app[web.1]: npm ERR! backend#1.0.0 start: `node server.js`
2019-12-13T02:59:25.358057+00:00 app[web.1]: npm ERR! Exit status 1
2019-12-13T02:59:25.358220+00:00 app[web.1]: npm ERR!
2019-12-13T02:59:25.358348+00:00 app[web.1]: npm ERR! Failed at the backend#1.0.0 start script.
2019-12-13T02:59:25.358480+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-12-13T02:59:25.362742+00:00 app[web.1]:
2019-12-13T02:59:25.362837+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-12-13T02:59:25.362931+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-12-13T02_59_25_359Z-debug.log
2019-12-13T02:59:25.446611+00:00 heroku[web.1]: State changed from starting to crashed
2019-12-13T02:59:25.422394+00:00 heroku[web.1]: Process exited with status 1
2019-12-13T03:00:38.195196+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=shrinkurlapp.herokuapp.com request_id=99378587-a922-4ad8-8445-aca15eba268a fwd="98.210.22.60" dyno= connect= service= status=503 bytes= protocol=https
2019-12-13T03:00:38.710170+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=shrinkurlapp.herokuapp.com request_id=ba6a84fe-9a4b-433d-a00d-1a6231e0317c fwd="98.210.22.60" dyno= connect= service= status=503 bytes= protocol=https
2019-12-13T03:00:49.612623+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=shrinkurlapp.herokuapp.com request_id=7fb228bc-9e62-4526-a51e-feff9631e266 fwd="98.210.22.60" dyno= connect= service= status=503 bytes= protocol=https
2019-12-13T03:00:50.201204+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=shrinkurlapp.herokuapp.com request_id=ada57278-8d33-4569-b3e3-bad6b136a234 fwd="98.210.22.60" dyno= connect= service= status=503 bytes= protocol=https
2019-12-13T03:03:11.014926+00:00 heroku[web.1]: State changed from crashed to starting
2019-12-13T03:03:13.149581+00:00 heroku[web.1]: Starting process with command `npm start`
2019-12-13T03:03:15.545496+00:00 app[web.1]:
2019-12-13T03:03:15.545520+00:00 app[web.1]: > backend#1.0.0 start /app
2019-12-13T03:03:15.545522+00:00 app[web.1]: > node server.js
2019-12-13T03:03:15.545524+00:00 app[web.1]:
2019-12-13T03:03:16.082886+00:00 app[web.1]:
2019-12-13T03:03:16.082936+00:00 app[web.1]: /app/node_modules/mongoose/lib/connection.js:541
2019-12-13T03:03:16.082939+00:00 app[web.1]: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' +
2019-12-13T03:03:16.082942+00:00 app[web.1]: ^
2019-12-13T03:03:16.086177+00:00 app[web.1]: Error [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.
2019-12-13T03:03:16.086180+00:00 app[web.1]: at new MongooseError (/app/node_modules/mongoose/lib/error/mongooseError.js:10:11)
2019-12-13T03:03:16.086183+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:541:11)
2019-12-13T03:03:16.086185+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:328:15)
2019-12-13T03:03:16.086187+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:16:10)
2019-12-13T03:03:16.086189+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:959:30)
2019-12-13T03:03:16.086191+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
2019-12-13T03:03:16.086193+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:815:32)
2019-12-13T03:03:16.086195+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:727:14)
2019-12-13T03:03:16.086197+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
2019-12-13T03:03:16.086200+00:00 app[web.1]: at internal/main/run_main_module.js:17:11 {
2019-12-13T03:03:16.086203+00:00 app[web.1]: message: '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.',
2019-12-13T03:03:16.086205+00:00 app[web.1]: name: 'MongooseError'
2019-12-13T03:03:16.086207+00:00 app[web.1]: }
2019-12-13T03:03:16.092626+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-12-13T03:03:16.092996+00:00 app[web.1]: npm ERR! errno 1
2019-12-13T03:03:16.094046+00:00 app[web.1]: npm ERR! backend#1.0.0 start: `node server.js`
2019-12-13T03:03:16.094306+00:00 app[web.1]: npm ERR! Exit status 1
2019-12-13T03:03:16.094539+00:00 app[web.1]: npm ERR!
2019-12-13T03:03:16.094740+00:00 app[web.1]: npm ERR! Failed at the backend#1.0.0 start script.
2019-12-13T03:03:16.094919+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-12-13T03:03:16.104750+00:00 app[web.1]:
2019-12-13T03:03:16.105020+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-12-13T03:03:16.105275+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-12-13T03_03_16_095Z-debug.log
2019-12-13T03:03:16.178860+00:00 heroku[web.1]: State changed from starting to crashed
2019-12-13T03:03:16.164865+00:00 heroku[web.1]: Process exited with status 1
2019-12-13T03:03:24.145385+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=shrinkurlapp.herokuapp.com request_id=ca564a1c-156c-484a-9354-ce243b3b1ed5 fwd="98.210.22.60" dyno= connect= service= status=503 bytes= protocol=https
2019-12-13T03:03:24.586560+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=shrinkurlapp.herokuapp.com request_id=bb81ead2-cd04-462f-9ab9-64b84d9238bb fwd="98.210.22.60" dyno= connect= service= status=503 bytes= protocol=https
2019-12-13T03:08:40.000000+00:00 app[api]: Build started by user deon.choi#gmail.com
2019-12-13T03:08:55.468949+00:00 app[api]: Deploy 67508aba by user deon.choi#gmail.com
2019-12-13T03:08:55.468949+00:00 app[api]: Release v4 created by user deon.choi#gmail.com
2019-12-13T03:08:55.741086+00:00 heroku[web.1]: State changed from crashed to starting
2019-12-13T03:08:56.000000+00:00 app[api]: Build succeeded
2019-12-13T03:08:57.971434+00:00 heroku[web.1]: Starting process with command `npm start`
2019-12-13T03:08:59.915432+00:00 app[web.1]:
2019-12-13T03:08:59.915464+00:00 app[web.1]: > backend#1.0.0 start /app
2019-12-13T03:08:59.915467+00:00 app[web.1]: > node server.js
2019-12-13T03:08:59.915470+00:00 app[web.1]:
2019-12-13T03:09:00.319828+00:00 app[web.1]:
2019-12-13T03:09:00.319851+00:00 app[web.1]: /app/node_modules/mongoose/lib/connection.js:541
2019-12-13T03:09:00.319854+00:00 app[web.1]: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' +
2019-12-13T03:09:00.319857+00:00 app[web.1]: ^
2019-12-13T03:09:00.322625+00:00 app[web.1]: Error [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.
2019-12-13T03:09:00.322629+00:00 app[web.1]: at new MongooseError (/app/node_modules/mongoose/lib/error/mongooseError.js:10:11)
2019-12-13T03:09:00.322632+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:541:11)
2019-12-13T03:09:00.322634+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:328:15)
2019-12-13T03:09:00.322636+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:18:10)
2019-12-13T03:09:00.322639+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:959:30)
2019-12-13T03:09:00.322641+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
2019-12-13T03:09:00.322644+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:815:32)
2019-12-13T03:09:00.322646+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:727:14)
2019-12-13T03:09:00.322648+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
2019-12-13T03:09:00.322651+00:00 app[web.1]: at internal/main/run_main_module.js:17:11 {
2019-12-13T03:09:00.322654+00:00 app[web.1]: message: '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.',
2019-12-13T03:09:00.322657+00:00 app[web.1]: name: 'MongooseError'
2019-12-13T03:09:00.322660+00:00 app[web.1]: }
2019-12-13T03:09:00.331200+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-12-13T03:09:00.331487+00:00 app[web.1]: npm ERR! errno 1
2019-12-13T03:09:00.333012+00:00 app[web.1]: npm ERR! backend#1.0.0 start: `node server.js`
2019-12-13T03:09:00.333312+00:00 app[web.1]: npm ERR! Exit status 1
2019-12-13T03:09:00.333487+00:00 app[web.1]: npm ERR!
2019-12-13T03:09:00.333633+00:00 app[web.1]: npm ERR! Failed at the backend#1.0.0 start script.
2019-12-13T03:09:00.333752+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-12-13T03:09:00.341621+00:00 app[web.1]:
2019-12-13T03:09:00.341770+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-12-13T03:09:00.341887+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-12-13T03_09_00_334Z-debug.log
2019-12-13T03:09:00.424560+00:00 heroku[web.1]: State changed from starting to crashed
2019-12-13T03:09:00.403174+00:00 heroku[web.1]: Process exited with status 1
2019-12-13T03:09:01.483310+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=shrinkurlapp.herokuapp.com request_id=79b75979-00fa-4994-a5d1-4f73c5841172 fwd="98.210.22.60" dyno= connect= service= status=503 bytes= protocol=https
2019-12-13T03:09:02.191776+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=shrinkurlapp.herokuapp.com request_id=93cf4327-3365-4174-a2df-7545952b00a6 fwd="98.210.22.60" dyno= connect= service= status=503 bytes= protocol=https
2019-12-13T03:09:03.076316+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=shrinkurlapp.herokuapp.com request_id=a2492372-c679-4144-acd1-7956692ad1e0 fwd="98.210.22.60" dyno= connect= service= status=503 bytes= protocol=https
2019-12-13T03:09:03.469741+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=shrinkurlapp.herokuapp.com request_id=d14e6638-96d5-4f19-8701-03ab766969fc fwd="98.210.22.60" dyno= connect= service= status=503 bytes= protocol=https
2019-12-13T03:09:47.050280+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=shrinkurlapp.herokuapp.com request_id=287c82b4-b3a6-42cc-81c5-ed97f310f7d3 fwd="98.210.22.60" dyno= connect= service= status=503 bytes= protocol=https
2019-12-13T03:09:47.349496+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=shrinkurlapp.herokuapp.com request_id=b1ced555-16fd-4255-92be-486d0917aff1 fwd="98.210.22.60" dyno= connect= service= status=503 bytes= protocol=https
I thought the issue was with my mongoose.connect() statement but it seems as if that is not the case.
Here is my server.js express file:
const express = require('express');
const cors = require('cors');
const mongoose = require('mongoose');
const cookieParser = require('cookie-parser');
const path = require('path');
require('dotenv').config();
const app = express();
const port = process.env.PORT || 3000;
app.use(cors());
app.use(express.json());
app.use(cookieParser());
const dbURI = process.env.DB_CONNECTION;
mongoose.connect(dbURI, {useNewUrlParser: true, useUnifiedTopology: true});
const connection = mongoose.connection;
connection.once('open', () => {
console.log('MongoDB database connection established successfully');
});
const urlsRouter = require('./routes/urls');
const redirectRouter = require('./routes/index');
const authRoute = require('./routes/auth');
app.use('/api/urls', urlsRouter);
app.use('/api/user', authRoute);
app.use('/api', redirectRouter);
app.use(express.static(path.join(__dirname, 'build')));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'build', 'index.html'));
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`)
});
refer the following to set environment variable to be used:
https://devcenter.heroku.com/articles/config-vars
The env variable that requires to be set is : DB_CONNECTION

NodeJS+React+Socket.io app doesn't work on Heroku

I wrote a simple NodeJs web app using React. I use Socket.io in this app to connect client to the server. The following codes are for my server.js and the component which connects to the server :
Server.js :
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var index = require('./routes/index');
var socket = require('./common/socket');
var exphbs = require('express-handlebars');
var app = express();
require('node-jsx').install();
var port = process.env.PORT || 9091;
var io = require('socket.io').listen(app.listen(port, function(){
console.log('Server is listening on port: ' + port);
}));
io.sockets.on('connection', function(sock){
socket(sock , io);
});
io.configure(function () {
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
});
// view engine setup
app.engine('handlebars', exphbs({defaultLayout: 'main', extname: '.handlebars'}));
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'handlebars');
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', index);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
console.log(err.message);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;
Component.js :
'use strict';
var React = require('react');
var io = require('socket.io-client');
var socket;
var UserRow = require('./userRow');
var SimpleUserList = React.createClass({
displayName: 'SimpleUserList',
componentDidMount: function() {
socket = io.connect();
socket.on('userList', function(data) {
console.log('userlist received');
}.bind(this));
},
componentWillUnmount: function() {
socket.close();
},
render: function() {
return (<div></div>);
}
module.exports = SimpleUserList;
main.handlebars :
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="stylesheets/style.css">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
{{{ body }}}
<script src="https://cdn.socket.io/socket.io-1.0.0.js"></script>
<script src="javascripts/bundle.js"></script>
</body>
</html>
The handle bar is not important, I just wanted to show what script file I include in my html file.
Any idea why I cannot connect to the heroku server?
heroku log :
2015-07-29T10:59:30.153481+00:00 app[web.1]: > npm run-script build | node server.js
2015-07-29T10:59:30.153482+00:00 app[web.1]:
2015-07-29T10:59:39.356552+00:00 app[web.1]: /app/server.js:22
2015-07-29T10:59:39.356556+00:00 app[web.1]: io.configure(function () {
2015-07-29T10:59:39.356558+00:00 app[web.1]: ^
2015-07-29T10:59:39.356560+00:00 app[web.1]: TypeError: undefined is not a function
2015-07-29T10:59:39.356561+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:22:4)
2015-07-29T10:59:39.356565+00:00 app[web.1]: at Object.Module._extensions..js (module.js:478:10)
2015-07-29T10:59:39.356590+00:00 app[web.1]: at Module.load (module.js:355:32)
2015-07-29T10:59:39.356595+00:00 app[web.1]: at startup (node.js:129:16)
2015-07-29T10:59:39.356563+00:00 app[web.1]: at Module._compile (module.js:460:26)
2015-07-29T10:59:39.356593+00:00 app[web.1]: at Function.Module.runMain (module.js:501:10)
2015-07-29T10:59:39.356596+00:00 app[web.1]: at node.js:814:3
2015-07-29T10:59:39.356592+00:00 app[web.1]: at Function.Module._load (module.js:310:12)
2015-07-29T10:59:44.937645+00:00 app[web.1]: npm ERR! Linux 3.13.0-49-generic
2015-07-29T10:59:44.817354+00:00 app[web.1]: util.print: Use console.log instead
2015-07-29T10:59:44.932214+00:00 app[web.1]:
2015-07-29T10:59:44.938157+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2015-07-29T10:59:44.938399+00:00 app[web.1]: npm ERR! node v0.12.7
2015-07-29T10:59:44.938826+00:00 app[web.1]: npm ERR! npm v2.11.3
2015-07-29T10:59:44.939022+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2015-07-29T10:59:44.939233+00:00 app[web.1]: npm ERR! simple-user-list#0.0.0 start: `npm run-script build | node server.js `
2015-07-29T10:59:44.939499+00:00 app[web.1]: npm ERR! Exit status 1
2015-07-29T10:59:44.939661+00:00 app[web.1]: npm ERR!
2015-07-29T10:59:44.939844+00:00 app[web.1]: npm ERR! Failed at the simple-user-list#0.0.0 start script 'npm run-script build | node server.js '.
2015-07-29T10:59:44.940270+00:00 app[web.1]: npm ERR! This is most likely a problem with the simple-user-list package,
2015-07-29T10:59:44.940497+00:00 app[web.1]: npm ERR! not with npm itself.
2015-07-29T10:59:44.940649+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2015-07-29T10:59:44.940834+00:00 app[web.1]: npm ERR! npm run-script build | node server.js
2015-07-29T10:59:44.940988+00:00 app[web.1]: npm ERR! You can get their info via:
2015-07-29T10:59:44.941492+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2015-07-29T10:59:44.944584+00:00 app[web.1]:
2015-07-29T10:59:44.941149+00:00 app[web.1]: npm ERR! npm owner ls simple-user-list
2015-07-29T10:59:44.944830+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2015-07-29T10:59:44.944952+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2015-07-29T10:59:45.817817+00:00 heroku[web.1]: Process exited with status 1
2015-07-29T10:59:45.831953+00:00 heroku[web.1]: State changed from starting to crashed
2015-07-29T10:59:47.593870+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=simple-user-list.herokuapp.com request_id=bd0cf3d6-0b8b-4fc0-aa37-a940cd5f328f fwd="50.19.169.132" dyno= connect= service= status=503 bytes=
2015-07-29T10:59:57.607136+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=simple-user-list.herokuapp.com request_id=8f80ec43-0eb8-4375-9341-7c1c2ecb81f0 fwd="50.19.169.132" dyno= connect= service= status=503 bytes=
2015-07-29T11:00:07.626517+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=simple-user-list.herokuapp.com request_id=4ee95d7b-e757-4590-b9e9-f48f491a3654 fwd="50.19.169.132" dyno= connect= service= status=503 bytes=
2015-07-29T11:00:17.650806+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=simple-user-list.herokuapp.com request_id=bdebebe0-6b5b-444b-81f2-fb34d3b00bb4 fwd="50.19.169.132" dyno= connect= service= status=503 bytes=
2015-07-29T11:00:27.660163+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=simple-user-list.herokuapp.com request_id=289949c3-1dac-4f3c-bb89-f6093da2c997 fwd="50.19.169.132" dyno= connect= service= status=503 bytes=
2015-07-29T11:00:37.669828+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=simple-user-list.herokuapp.com request_id=997d267f-81fb-40e4-9c7d-85f9803653f8 fwd="50.19.169.132" dyno= connect= service= status=503 bytes=
2015-07-29T11:06:28.718078+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=simple-user-list.herokuapp.com request_id=c0f10a34-914a-439b-8a59-5ef954d994e8 fwd="207.6.39.42" dyno= connect= service= status=503 bytes=
2015-07-29T11:10:46.273821+00:00 heroku[web.1]: State changed from crashed to starting
2015-07-29T11:10:49.577787+00:00 heroku[web.1]: Starting process with command `npm start`
2015-07-29T11:10:51.591809+00:00 app[web.1]:
2015-07-29T11:10:51.591830+00:00 app[web.1]: > simple-user-list#0.0.0 start /app
2015-07-29T11:10:51.591832+00:00 app[web.1]: > npm run-script build | node server.js
2015-07-29T11:10:51.591833+00:00 app[web.1]:
2015-07-29T11:10:57.340680+00:00 app[web.1]: /app/server.js:22
2015-07-29T11:10:57.340683+00:00 app[web.1]: io.configure(function () {
2015-07-29T11:10:57.340685+00:00 app[web.1]: ^
2015-07-29T11:10:57.340687+00:00 app[web.1]: TypeError: undefined is not a function
2015-07-29T11:10:57.340689+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:22:4)
2015-07-29T11:10:57.340692+00:00 app[web.1]: at Object.Module._extensions..js (module.js:478:10)
2015-07-29T11:10:57.340693+00:00 app[web.1]: at Module.load (module.js:355:32)
2015-07-29T11:10:57.340690+00:00 app[web.1]: at Module._compile (module.js:460:26)
2015-07-29T11:10:57.340695+00:00 app[web.1]: at Function.Module._load (module.js:310:12)
2015-07-29T11:10:57.340696+00:00 app[web.1]: at Function.Module.runMain (module.js:501:10)
2015-07-29T11:10:57.340697+00:00 app[web.1]: at startup (node.js:129:16)
2015-07-29T11:10:57.340699+00:00 app[web.1]: at node.js:814:3
2015-07-29T11:11:02.957215+00:00 app[web.1]: util.print: Use console.log instead
2015-07-29T11:11:03.080961+00:00 app[web.1]: npm ERR! Linux 3.13.0-57-generic
2015-07-29T11:11:03.088435+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2015-07-29T11:11:03.088566+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2015-07-29T11:11:03.074299+00:00 app[web.1]:
2015-07-29T11:11:03.081974+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2015-07-29T11:11:03.082248+00:00 app[web.1]: npm ERR! node v0.12.7
2015-07-29T11:11:03.082698+00:00 app[web.1]: npm ERR! npm v2.11.3
2015-07-29T11:11:03.082883+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2015-07-29T11:11:03.083205+00:00 app[web.1]: npm ERR! simple-user-list#0.0.0 start: `npm run-script build | node server.js `
2015-07-29T11:11:03.083354+00:00 app[web.1]: npm ERR! Exit status 1
2015-07-29T11:11:03.083515+00:00 app[web.1]: npm ERR!
2015-07-29T11:11:03.083669+00:00 app[web.1]: npm ERR! Failed at the simple-user-list#0.0.0 start script 'npm run-script build | node server.js '.
2015-07-29T11:11:03.084247+00:00 app[web.1]: npm ERR! not with npm itself.
2015-07-29T11:11:03.084376+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2015-07-29T11:11:03.083969+00:00 app[web.1]: npm ERR! This is most likely a problem with the simple-user-list package,
2015-07-29T11:11:03.085055+00:00 app[web.1]: npm ERR! You can get their info via:
2015-07-29T11:11:03.084565+00:00 app[web.1]: npm ERR! npm run-script build | node server.js
2015-07-29T11:11:03.085058+00:00 app[web.1]: npm ERR! npm owner ls simple-user-list
2015-07-29T11:11:03.085128+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2015-07-29T11:11:03.088091+00:00 app[web.1]:
2015-07-29T11:11:03.853402+00:00 heroku[web.1]: Process exited with status 1
2015-07-29T11:11:03.866414+00:00 heroku[web.1]: State changed from starting to crashed
2015-07-29T11:16:15.196180+00:00 heroku[slug-compiler]: Slug compilation started
2015-07-29T11:16:15.196195+00:00 heroku[slug-compiler]: Slug compilation finished
2015-07-29T11:16:15.153339+00:00 heroku[api]: Deploy a6fb15c by aryan.hosseinzadeh#gmail.com
2015-07-29T11:16:15.153339+00:00 heroku[api]: Release v15 created by aryan.hosseinzadeh#gmail.com
2015-07-29T11:16:15.571381+00:00 heroku[web.1]: State changed from crashed to starting
2015-07-29T11:16:19.908038+00:00 heroku[web.1]: Starting process with command `npm start`
2015-07-29T11:16:22.344144+00:00 app[web.1]:
2015-07-29T11:16:22.344166+00:00 app[web.1]: > simple-user-list#0.0.0 start /app
2015-07-29T11:16:22.344168+00:00 app[web.1]: > npm run-script build | node server.js
2015-07-29T11:16:22.344170+00:00 app[web.1]:
2015-07-29T11:16:28.997464+00:00 app[web.1]: Option polling duration is not valid. Please refer to the README.
2015-07-29T11:16:29.378774+00:00 heroku[web.1]: State changed from starting to up
2015-07-29T11:16:29.671752+00:00 app[web.1]: Server is listening on port: 9807
2015-07-29T11:16:30.880399+00:00 heroku[router]: at=info method=GET path="/" host=simple-user-list.herokuapp.com request_id=8286e365-9790-487e-9b71-a69a4de800fc fwd="54.144.80.213" dyno=web.1 connect=6ms service=227ms status=200 bytes=2017
2015-07-29T11:16:30.910262+00:00 app[web.1]: GET / 200 252.009 ms - 1821
2015-07-29T11:16:34.120554+00:00 app[web.1]: util.print: Use console.log instead
So , it's solved.
There was no need to explicitly refer to {host}/socket/socket.io and there was no need to specify io.config (at least so far) and also there was no need to specify host address on client side (io.connect is good enough).

Resources