ECONNREFUSED when trying to deploy to heroku - javascript

I'd really appreciate any help/insight.
I'm trying to push an application to Heroku, but for some reason, no matter what I try, I keep getting the error below:
2022-05-23T14:27:01.516414+00:00 app[web.1]: port: 3306,
2022-05-23T14:27:01.516414+00:00 app[web.1]: fatal: true
2022-05-23T14:27:01.516415+00:00 app[web.1]: }
2022-05-23T14:27:01.516415+00:00 app[web.1]: }
2022-05-23T14:27:01.661606+00:00 heroku[web.1]: Process exited with status 1
2022-05-23T14:27:01.740162+00:00 heroku[web.1]: State changed from starting to crashed
2022-05-23T14:27:02.914707+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nameless-ravine-28520.herokuapp.com request_id=98b37974-ba16-45f7-acf3-e7e86339662f fwd="24.16.97.212" dyno= connect= service= status=503 bytes= protocol=https
2022-05-23T14:27:03.266073+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nameless-ravine-28520.herokuapp.com request_id=8cd1f4ab-cebf-4e1f-921f-7882755f3ba7 fwd="24.16.97.212" dyno= connect= service= status=503 bytes= protocol=https
2022-05-23T14:27:49.000000+00:00 app[api]: Build started by user myemail#gmail.com
2022-05-23T14:28:03.242164+00:00 app[api]: Deploy 94abcb92 by user myemail#gmail.com
2022-05-23T14:28:03.242164+00:00 app[api]: Release v18 created by user myemail#gmail.com
2022-05-23T14:28:03.655978+00:00 heroku[web.1]: State changed from crashed to starting
2022-05-23T14:28:04.000000+00:00 app[api]: Build succeeded
2022-05-23T14:28:05.900985+00:00 heroku[web.1]: Starting process with command `npm start`
2022-05-23T14:28:07.670709+00:00 app[web.1]:
2022-05-23T14:28:07.670783+00:00 app[web.1]: > tech-blog#1.0.0 start
2022-05-23T14:28:07.670793+00:00 app[web.1]: > node server.js
2022-05-23T14:28:07.670793+00:00 app[web.1]:
2022-05-23T14:28:08.224358+00:00 app[web.1]: /app/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:92
2022-05-23T14:28:08.224360+00:00 app[web.1]: throw new SequelizeErrors.ConnectionRefusedError(err);
2022-05-23T14:28:08.224361+00:00 app[web.1]: ^
2022-05-23T14:28:08.224361+00:00 app[web.1]:
2022-05-23T14:28:08.224362+00:00 app[web.1]: ConnectionRefusedError [SequelizeConnectionRefusedError]: connect ECONNREFUSED 127.0.0.1:4000
2022-05-23T14:28:08.224362+00:00 app[web.1]: at ConnectionManager.connect (/app/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:92:17)
2022-05-23T14:28:08.224363+00:00 app[web.1]: at processTicksAndRejections (node:internal/process/task_queues:96:5)
2022-05-23T14:28:08.224365+00:00 app[web.1]: at async ConnectionManager._connect (/app/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:216:24)
2022-05-23T14:28:08.224365+00:00 app[web.1]: at async /app/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:174:32
2022-05-23T14:28:08.224365+00:00 app[web.1]: at async ConnectionManager.getConnection (/app/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:197:7)
2022-05-23T14:28:08.224365+00:00 app[web.1]: at async /app/node_modules/sequelize/lib/sequelize.js:300:26
2022-05-23T14:28:08.224366+00:00 app[web.1]: at async MySQLQueryInterface.createTable (/app/node_modules/sequelize/lib/dialects/abstract/query-interface.js:94:12)
2022-05-23T14:28:08.224366+00:00 app[web.1]: at async Function.sync (/app/node_modules/sequelize/lib/model.js:937:5)
2022-05-23T14:28:08.224366+00:00 app[web.1]: at async Sequelize.sync (/app/node_modules/sequelize/lib/sequelize.js:374:9) {
2022-05-23T14:28:08.224367+00:00 app[web.1]: parent: Error: connect ECONNREFUSED 127.0.0.1:4000
2022-05-23T14:28:08.224367+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16) {
2022-05-23T14:28:08.224367+00:00 app[web.1]: errno: -111,
2022-05-23T14:28:08.224368+00:00 app[web.1]: code: 'ECONNREFUSED',
2022-05-23T14:28:08.224368+00:00 app[web.1]: syscall: 'connect',
2022-05-23T14:28:08.224368+00:00 app[web.1]: address: '127.0.0.1',
2022-05-23T14:28:08.224368+00:00 app[web.1]: port: 4000,
2022-05-23T14:28:08.224369+00:00 app[web.1]: fatal: true
2022-05-23T14:28:08.224369+00:00 app[web.1]: },
2022-05-23T14:28:08.224369+00:00 app[web.1]: original: Error: connect ECONNREFUSED 127.0.0.1:4000
2022-05-23T14:28:08.224369+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16) {
2022-05-23T14:28:08.224370+00:00 app[web.1]: errno: -111,
2022-05-23T14:28:08.224370+00:00 app[web.1]: code: 'ECONNREFUSED',
2022-05-23T14:28:08.224370+00:00 app[web.1]: syscall: 'connect',
2022-05-23T14:28:08.224370+00:00 app[web.1]: address: '127.0.0.1',
2022-05-23T14:28:08.224371+00:00 app[web.1]: port: 4000,
2022-05-23T14:28:08.224371+00:00 app[web.1]: fatal: true
2022-05-23T14:28:08.224371+00:00 app[web.1]: }
2022-05-23T14:28:08.224371+00:00 app[web.1]: }
2022-05-23T14:28:08.359638+00:00 heroku[web.1]: Process exited with status 1
2022-05-23T14:28:08.432804+00:00 heroku[web.1]: State changed from starting to crashed
2022-05-23T14:28:09.878995+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nameless-ravine-28520.herokuapp.com request_id=bf095c36-5ad7-4489-b641-3f4081406547 fwd="24.16.97.212" dyno= connect= service= status=503 bytes= protocol=https
2022-05-23T14:28:10.284737+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nameless-ravine-28520.herokuapp.com request_id=76849bc7-a25c-4705-83c2-e02436ca911d fwd="24.16.97.212" dyno= connect= service= status=503 bytes= protocol=https
2022-05-23T14:31:33.010867+00:00 heroku[web.1]: State changed from crashed to starting
2022-05-23T14:31:36.816915+00:00 heroku[web.1]: Starting process with command `npm start`
2022-05-23T14:31:38.599632+00:00 app[web.1]:
2022-05-23T14:31:38.599649+00:00 app[web.1]: > tech-blog#1.0.0 start
2022-05-23T14:31:38.599649+00:00 app[web.1]: > node server.js
2022-05-23T14:31:38.599650+00:00 app[web.1]:
2022-05-23T14:31:39.723960+00:00 app[web.1]: /app/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:92
2022-05-23T14:31:39.724079+00:00 app[web.1]: throw new SequelizeErrors.ConnectionRefusedError(err);
2022-05-23T14:31:39.724080+00:00 app[web.1]: ^
2022-05-23T14:31:39.724081+00:00 app[web.1]:
2022-05-23T14:31:39.724082+00:00 app[web.1]: ConnectionRefusedError [SequelizeConnectionRefusedError]: connect ECONNREFUSED 127.0.0.1:3306
2022-05-23T14:31:39.724082+00:00 app[web.1]: at ConnectionManager.connect (/app/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:92:17)
2022-05-23T14:31:39.724083+00:00 app[web.1]: at processTicksAndRejections (node:internal/process/task_queues:96:5)
2022-05-23T14:31:39.724093+00:00 app[web.1]: at async ConnectionManager._connect (/app/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:216:24)
2022-05-23T14:31:39.724094+00:00 app[web.1]: at async /app/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:174:32
2022-05-23T14:31:39.724094+00:00 app[web.1]: at async ConnectionManager.getConnection (/app/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:197:7)
2022-05-23T14:31:39.724094+00:00 app[web.1]: at async /app/node_modules/sequelize/lib/sequelize.js:301:26
2022-05-23T14:31:39.724095+00:00 app[web.1]: at async MySQLQueryInterface.tableExists (/app/node_modules/sequelize/lib/dialects/abstract/query-interface.js:102:17)
2022-05-23T14:31:39.724095+00:00 app[web.1]: at async Function.sync (/app/node_modules/sequelize/lib/model.js:939:21)
2022-05-23T14:31:39.724095+00:00 app[web.1]: at async Sequelize.sync (/app/node_modules/sequelize/lib/sequelize.js:373:9) {
2022-05-23T14:31:39.724096+00:00 app[web.1]: parent: Error: connect ECONNREFUSED 127.0.0.1:3306
2022-05-23T14:31:39.724096+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16) {
2022-05-23T14:31:39.724096+00:00 app[web.1]: errno: -111,
2022-05-23T14:31:39.724097+00:00 app[web.1]: code: 'ECONNREFUSED',
2022-05-23T14:31:39.724097+00:00 app[web.1]: syscall: 'connect',
2022-05-23T14:31:39.724097+00:00 app[web.1]: address: '127.0.0.1',
2022-05-23T14:31:39.724098+00:00 app[web.1]: port: 3306,
2022-05-23T14:31:39.724098+00:00 app[web.1]: fatal: true
2022-05-23T14:31:39.724098+00:00 app[web.1]: },
2022-05-23T14:31:39.724098+00:00 app[web.1]: original: Error: connect ECONNREFUSED 127.0.0.1:3306
2022-05-23T14:31:39.724099+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16) {
2022-05-23T14:31:39.724099+00:00 app[web.1]: errno: -111,
2022-05-23T14:31:39.724099+00:00 app[web.1]: code: 'ECONNREFUSED',
2022-05-23T14:31:39.724099+00:00 app[web.1]: syscall: 'connect',
2022-05-23T14:31:39.724100+00:00 app[web.1]: address: '127.0.0.1',
2022-05-23T14:31:39.724100+00:00 app[web.1]: port: 3306,
2022-05-23T14:31:39.724100+00:00 app[web.1]: fatal: true
2022-05-23T14:31:39.724100+00:00 app[web.1]: }
2022-05-23T14:31:39.724101+00:00 app[web.1]: }
2022-05-23T14:31:39.724107+00:00 app[web.1]:
2022-05-23T14:31:39.724107+00:00 app[web.1]: Node.js v17.7.2
2022-05-23T14:31:39.860343+00:00 heroku[web.1]: Process exited with status 1
2022-05-23T14:31:40.053008+00:00 heroku[web.1]: State changed from starting to crashed
2022-05-23T14:31:45.111051+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nameless-ravine-28520.herokuapp.com request_id=5336970d-ba74-4b0a-a94d-bf59e04b5de3 fwd="24.16.97.212" dyno= connect= service= status=503 bytes= protocol=https
2022-05-23T14:31:45.471297+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nameless-ravine-28520.herokuapp.com request_id=5dbf9333-0832-4a06-86be-71001fa9b245 fwd="24.16.97.212" dyno= connect= service= status=503 bytes= protocol=https
2022-05-23T14:31:07.000000+00:00 app[api]: Build started by user myemail#gmail.com
I spent almost the entire weekend looking at this and can't seem to figure it out. I've asked colleagues and none of their suggestions have worked, despite them having similar setups and being able to deploy to Heroku without issues.
Here's my /config/connection.js file:
const Sequelize = require('sequelize');
require('dotenv').config();
// create connection to our db
const sequelize = process.env.JAWSDB_URL
? new Sequelize(process.env.JAWSDB_URL)
: new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PW, {
host: '127.0.0.1.',
port: 3306,
dialect: 'mysql'
});
module.exports = sequelize;
And here's my server.js file:
const path = require('path');
const express = require('express');
const session = require('express-session');
const exphbs = require('express-handlebars');
const app = express();
const PORT = process.env.PORT || 4000;
const sequelize = require('./config/connection');
const SequelizeStore = require('connect-session-sequelize')(session.Store);
const helpers = require('./utils/helpers');
const hbs = exphbs.create({ helpers });
const sess = {
secret: 'Super secret secret',
cookie: {
maxAge: 900000
},
resave: false,
saveUninitialized: true,
store: new SequelizeStore({
db: sequelize
})
};
app.use(session(sess));
app.engine('handlebars', hbs.engine);
app.set('view engine', 'handlebars');
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));
app.use(require('./controllers/'));
sequelize.sync({ force: false }).then(() => {
app.listen(PORT, () => console.log('Now listening'));
});
Alternatively, here's the github repo: https://github.com/ilantimerman/tech-blog

Related

8Cant deploy Nodejs server in Heroku : 'Error: Cannot find module 'getStream''

My project seems to have no issues when running locally, but when I try to deploy it in heroku and open the app it gives me an application error. I tried checking the logs in heroku and this is what I get.
2022-09-14T20:31:10.475090+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1028:19)
2022-09-14T20:31:10.475091+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:102:18)
2022-09-14T20:31:10.475091+00:00 app[web.1]: at Object.<anonymous> (/app/controllers/auth.js:1:19)
2022-09-14T20:31:10.475092+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1126:14)
2022-09-14T20:31:10.475092+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
2022-09-14T20:31:10.475092+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:1004:32)
2022-09-14T20:31:10.475093+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:839:12)
2022-09-14T20:31:10.475093+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1028:19) {
2022-09-14T20:31:10.475093+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2022-09-14T20:31:10.475094+00:00 app[web.1]: requireStack: [
2022-09-14T20:31:10.475094+00:00 app[web.1]: '/app/controllers/auth.js',
2022-09-14T20:31:10.475094+00:00 app[web.1]: '/app/routes/auth.js',
2022-09-14T20:31:10.475095+00:00 app[web.1]: '/app/index.js'
2022-09-14T20:31:10.475095+00:00 app[web.1]: ]
2022-09-14T20:31:10.475095+00:00 app[web.1]: }
2022-09-14T20:31:10.660749+00:00 heroku[web.1]: Process exited with status 1
2022-09-14T20:31:10.723193+00:00 heroku[web.1]: State changed from starting to crashed
2022-09-14T20:31:10.726441+00:00 heroku[web.1]: State changed from crashed to starting
2022-09-14T20:31:13.020405+00:00 heroku[web.1]: Starting process with command `npm start`
2022-09-14T20:31:16.234548+00:00 app[web.1]:
2022-09-14T20:31:16.234562+00:00 app[web.1]: > server#1.0.0 start
2022-09-14T20:31:16.234562+00:00 app[web.1]: > node index.js
2022-09-14T20:31:16.234563+00:00 app[web.1]:
2022-09-14T20:31:16.387441+00:00 app[web.1]: node:internal/modules/cjs/loader:959
2022-09-14T20:31:16.387443+00:00 app[web.1]: throw err;
2022-09-14T20:31:16.387444+00:00 app[web.1]: ^
2022-09-14T20:31:16.387444+00:00 app[web.1]:
2022-09-14T20:31:16.387444+00:00 app[web.1]: Error: Cannot find module 'getStream'
2022-09-14T20:31:16.387445+00:00 app[web.1]: Require stack:
2022-09-14T20:31:16.387445+00:00 app[web.1]: - /app/controllers/auth.js
2022-09-14T20:31:16.387446+00:00 app[web.1]: - /app/routes/auth.js
2022-09-14T20:31:16.387446+00:00 app[web.1]: - /app/index.js
2022-09-14T20:31:16.387446+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
2022-09-14T20:31:16.387447+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:804:27)
2022-09-14T20:31:16.387447+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1028:19)
2022-09-14T20:31:16.387448+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:102:18)
2022-09-14T20:31:16.387448+00:00 app[web.1]: at Object.<anonymous> (/app/controllers/auth.js:1:19)
2022-09-14T20:31:16.387448+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1126:14)
2022-09-14T20:31:16.387449+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
2022-09-14T20:31:16.387449+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:1004:32)
2022-09-14T20:31:16.387449+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:839:12)
2022-09-14T20:31:16.387449+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1028:19) {
2022-09-14T20:31:16.387450+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2022-09-14T20:31:16.387450+00:00 app[web.1]: requireStack: [
2022-09-14T20:31:16.387450+00:00 app[web.1]: '/app/controllers/auth.js',
2022-09-14T20:31:16.387450+00:00 app[web.1]: '/app/routes/auth.js',
2022-09-14T20:31:16.387451+00:00 app[web.1]: '/app/index.js'
2022-09-14T20:31:16.387451+00:00 app[web.1]: ]
2022-09-14T20:31:16.387451+00:00 app[web.1]: }
2022-09-14T20:31:16.528452+00:00 heroku[web.1]: Process exited with status 1
2022-09-14T20:31:16.728856+00:00 heroku[web.1]: State changed from starting to crashed
2022-09-14T20:31:55.119571+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET pad="190.237.25.187" dyno= connect= service= status=503 bytes= protocol=https2022-09-14T20:42:01.202592+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=file-iu-sys.herokuapp.com request_id=b157556e-1a74-4d16-aef5-7e2e8cea2612 fwd="190.237.25.187" dyno= connect= service= status=503 bytes= protocol=https 2022-09-14T20:42:02.113418+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=file-iu-sys.herokuapp.com request_id=2c0cf996-5b33-4d15-b7c6-88cedd9f9c25 fwd="190.237.25.187" dyno= connect= service= status=503 bytes= protocol=https
I have tried checking for missing scripts, changing the Port to process.env.PORT, heroku repo:reset, deleting the git file and starting a new git init and even deleting the node_modules folder and running npm install. A similar app I tried hosting in heroku seems to run with no problems, the difference being this one has a mysql dependency and the heroku app has a clearDB plugin. The 'getstream' version is '8.0.1' (the one that runs without problems is '8.0.0' could that be the issue?).
this is my package.json file:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^5.0.1",
"body-parser": "^1.20.0",
"cors": "^2.8.5",
"crypto": "^1.0.1",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"getstream": "^8.0.1",
"mysql": "^2.18.1",
"nodemon": "^2.0.16",
"stream-chat": "^6.5.1"
}
}
index.js file:
const express = require('express');
const cors = require('cors');
const mysql = require('mysql');
const bodyParser = require('body-parser')
const authRoutes = require('./routes/auth.js')
const connection = mysql.createPool({
host: '*host-name*',
user: '*user*',
password: '*password*',
database: '*database*'
})
const app = express();
const PORT = process.env.PORT || 3001;
require('dotenv').config();
app.use(cors());
app.use(express.json());
app.use(express.urlencoded());
//Routes
app.use('/auth', authRoutes);
app.get('/', (req, res) =>{
res.send('Server an')
})
//DB connection
//get from DB
app.get('/api/get', (req, res)=>{
const sqlSelect = 'SELECT * FROM anmeldungen';
connection.query(sqlSelect, (err, result)=>{
res.send(result);
if(err){
console.log('Error fetching from db');
}
});
})
//write to DB
app.use(bodyParser.urlencoded({extended: true}));
app.post('/api/insert', (req, res)=>{
const Student = req.body.Student;
const Fach = req.body.Fach;
//const Datum = req.body.Datum;
const Datum = new Date().toISOString().split('T')[0];
const DateiName = req.body.DateiName;
const Seite = req.body.Seite;
const Beschreibung = req.body.Beschreibung;
const sqlInsert = 'INSERT INTO anmeldungen(Student, Fach, Datum, DateiName, Seite, Beschreibung) VALUES(?,?,?,?,?,?)'
connection.query(sqlInsert, [Student, Fach, Datum, DateiName, Seite, Beschreibung], (err, result)=>{
console.log(result);
});
});
//delete from db
app.delete('/api/delete/:id', (req, res) =>{
const rowId = req.params.id;
const sqlDelete = "DELETE FROM anmeldungen WHERE id = ?";
connection.query(sqlDelete, rowId, (err, result)=>{
if(err) console.log(err);
})
})
//update rows in db
app.put('/api/update/:id', (req, res) =>{
const rowId = req.params.id;
const rowStat = req.body.Status;
const sqlUpdate = "UPDATE anmeldungen SET Status = ? WHERE id = ?";
connection.query(sqlUpdate, [rowStat, rowId], (err, result)=>{
if(err) console.log(err);
})
})
app.listen(PORT, () => console.log(`Server lauft auf port ${PORT}`));
auth.js:
const {connect} = require('getStream');
const bcrypt = require('bcrypt');
const StreamChat = require('stream-chat').StreamChat;
const crypto = require('crypto');
require('dotenv').config();
const api_key = process.env.STREAM_API_KEY;
const api_secret = process.env.STREAM_API_SECRET;
const app_id = process.env.STREAM_APP_ID;
const signup = async (req, res) => {
try {
//get from the front-end
const {fullName, username, password, phoneNumber} = req.body;
//create a random user Id: 16 digits in hexadecimal
const userId = crypto.randomBytes(16).toString('hex');
//connection to stream
const serverClient = connect(api_key, api_secret, app_id);
//create a password for the user token
const hashedPassword = await bcrypt.hash(password, 10);
//create token for the user
const token = serverClient.createUserToken(userId);
//get the values straight from the front-end to ensure secure authentication
res.status(200).json({token, fullName, username, userId, hashedPassword, phoneNumber})
} catch (error) {
console.log(error);
res.status(500).json({message: error});
}
};
const login = async(req, res) => {
try {
const {username, password} = req.body;
const serverClient = connect(api_key, api_secret, app_id);
//new instance of streamChat
const client = StreamChat.getInstance(api_key, api_secret);
//query all users that match this username
const {users} = await client.queryUsers({name: username});
if(!users.length) return res.status(400).json({message: 'Benutzername nicht gefunden.'});
//decrypt the password to see if it matches
const success = await bcrypt.compare(password, users[0].hashedPassword);
//create new token for this specific user's id.
const token = serverClient.createUserToken(users[0].id);
if(success){
res.status(200).json({token, fullName: users[0].fullName, username, userId: users[0].id});
} else {
res.status(500).json({message: 'falsches Kennwort'});
}
} catch (error) {
console.log(error);
res.status(500).json({message: error});
}
};
module.exports = {signup, login}
Found the problem in the auth.js file: I had written const {connect} = require('getStream'); instead of const {connect} = require('getstream');. So I guess it was due to naming conventions in a way. #Chris ty, that first question was right on the money.

heroku[web.1]: State changed from up to crashed

this is my command prompt:
2022-07-10T23:36:17.323791+00:00 heroku[web.1]: Process exited with status 1
2022-07-10T23:36:17.574484+00:00 heroku[web.1]: State changed from up to crashed
2022-07-10T23:36:17.578331+00:00 heroku[web.1]: State changed from crashed to starting
2022-07-10T23:36:19.862639+00:00 heroku[web.1]: Starting process with command `node server`
2022-07-10T23:36:21.568790+00:00 app[web.1]: Server running in development mode on port 52222
2022-07-10T23:36:22.148988+00:00 heroku[web.1]: State changed from starting to up
2022-07-10T23:36:51.593762+00:00 app[web.1]: MongooseServerSelectionError: connection <monitor> to 104.155.184.217:27017 closed
2022-07-10T23:36:51.593769+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:819:32)
2022-07-10T23:36:51.593771+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:378:10
2022-07-10T23:36:51.593773+00:00 app[web.1]: at /app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
2022-07-10T23:36:51.593773+00:00 app[web.1]: at new Promise (<anonymous>)
2022-07-10T23:36:51.593774+00:00 app[web.1]: at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
2022-07-10T23:36:51.593774+00:00 app[web.1]: at Mongoose._promiseOrCallback (/app/node_modules/mongoose/lib/index.js:1223:10)
2022-07-10T23:36:51.593774+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:377:20)
2022-07-10T23:36:51.593775+00:00 app[web.1]: at connectDB (/app/config/db.js:6:37)
2022-07-10T23:36:51.593775+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:10:1)
2022-07-10T23:36:51.593775+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1105:14) {
2022-07-10T23:36:51.593776+00:00 app[web.1]: reason: TopologyDescription {
2022-07-10T23:36:51.593777+00:00 app[web.1]: type: 'ReplicaSetNoPrimary',
2022-07-10T23:36:51.593777+00:00 app[web.1]: servers: Map(3) {
2022-07-10T23:36:51.593778+00:00 app[web.1]: 'ac-eqnecmx-shard-00-00.uqxpgna.mongodb.net:27017' => [ServerDescription],
2022-07-10T23:36:51.593778+00:00 app[web.1]: 'ac-eqnecmx-shard-00-01.uqxpgna.mongodb.net:27017' => [ServerDescription],
2022-07-10T23:36:51.593778+00:00 app[web.1]: 'ac-eqnecmx-shard-00-02.uqxpgna.mongodb.net:27017' => [ServerDescription]
2022-07-10T23:36:51.593779+00:00 app[web.1]: },
2022-07-10T23:36:51.593779+00:00 app[web.1]: stale: false,
2022-07-10T23:36:51.593780+00:00 app[web.1]: compatible: true,
2022-07-10T23:36:51.593780+00:00 app[web.1]: heartbeatFrequencyMS: 10000,
2022-07-10T23:36:51.593780+00:00 app[web.1]: localThresholdMS: 15,
2022-07-10T23:36:51.593781+00:00 app[web.1]: setName: 'atlas-qcim0h-shard-0',
2022-07-10T23:36:51.593781+00:00 app[web.1]: logicalSessionTimeoutMinutes: undefined
2022-07-10T23:36:51.593781+00:00 app[web.1]: },
2022-07-10T23:36:51.593781+00:00 app[web.1]: code: undefined
2022-07-10T23:36:51.593781+00:00 app[web.1]: }
2022-07-10T23:36:51.889734+00:00 heroku[web.1]: Process exited with status 1
2022-07-10T23:36:51.942371+00:00 heroku[web.1]: State changed from up to crashed
2022-07-10T23:47:28.294565+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=pomoworko.herokuapp.com request_id=f70e80ad-c7f4-475d-b830-1b1cad21a5cc fwd="181.56.0.86" dyno= connect= service= status=503 bytes= protocol=https
this is my code:
Procfile:
web:node server
.gitignore:
node_modules/
server.js
const express = require('express')
const morgan = require('morgan')
const cors = require('cors')
const connectDB = require('./config/db')
const passport = require('passport')
const bodyParser = require('body-parser')
const routes = require('./routes/index')
connectDB()
const app = express()
if(process.env.NODE_ENV === 'development') {
app.use(morgan('dev'))
}
app.use(cors())
app.use(bodyParser.urlencoded({extended: false}))
app.use(bodyParser.json())
app.use(routes)
app.use(passport.initialize())
require('./config/passport')(passport)
const PORT = process.env.PORT || 3000
app.listen(PORT, console.log(`Server running in ${process.env.NODE_ENV} mode on port ${PORT}`))
package.json:
{
"name": "flutterauth",
"version": "1.0.0",
"description": "Authentication system for flutter apps",
"main": "server.js",
"scripts": {
"start": "cross-env NODE_ENV=production node server",
"dev": "cross-env NODE_ENV=development nodemon server"
},
"author": "pomoworko",
"license": "MIT",
"dependencies": {
"bcrypt": "^5.0.1",
"body-parser": "^1.20.0",
"connect-mongo": "^4.6.0",
"cors": "^2.8.5",
"cross-env": "^7.0.3",
"express": "^4.18.1",
"jwt-simple": "^0.5.6",
"mongoose": "^6.4.4",
"morgan": "^1.10.0",
"nodemon": "^2.0.19",
"passport": "^0.6.0",
"passport-jwt": "^4.0.0"
}
}
For now, I got this:
If I write on the command prompt: "heroku restart", It works
And if I write on the command prompt: "heroku logs --tail", it shows me again, the first image, it doesn't work
How to fix this error
Thank you in advance
I'm assuming you are using mongodB atlas. You need to whitelist your IP address. To do that, head over to your network access tab, and include an IP address 0.0.0.0/0. This is a wild card IP address that would allow all IP addresses with the correct credentials to access your DB.
As such:
Note: This whitelists all IP addresses. It's alright when testing. But when going into production, you might want to whitelist only IP addresses that should have access to the cluster...for security purposes.

Querying a mongo DB causes Heroku timeout?

I'm using a simple node app with an express server and attempting to deploy it to heroku and a single query to the database causes my app to crash with an H13 error after about 10 seconds. The error says it closed without response.
crash logs:
2022-06-20T04:01:55.992187+00:00 app[web.1]: const err = new MongooseError(message);
2022-06-20T04:01:55.992188+00:00 app[web.1]: ^
2022-06-20T04:01:55.992189+00:00 app[web.1]:
2022-06-20T04:01:55.992190+00:00 app[web.1]: MongooseError: Operation `classifications.findOne()` bufdOne()` buffering timed out after 10000ms
2022-06-20T04:01:55.992191+00:00 app[web.1]: at Timeout.<anonymous> (/app/node_modules/mongoose/lib/dgoose/lib/drivers/node-mongodb-native/collection.js:151:23)
2022-06-20T04:01:55.992191+00:00 app[web.1]: at listOnTimeout (node:internal/timers:559:17)) 2022-06-20T
2022-06-20T04:01:55.992192+00:00 app[web.1]: at processTimers (node:internal/timers:502:7)2022-06-20T04:01:55.992196+00:00 app[web.1]:
2022-06-20T04:01:55.992197+00:00 app[web.1]: Node.js v17.7.2 without re
2022-06-20T04:01:56.002582+00:00 heroku[router]: at=error code=H13 desc="Connection closed728b0fb8-d2 without response" method=GET path="/al/classes/class-1a" host=wcsn-backend.herokuapp.com s=503 bytes
request_id=728b0fb8-d2bf-44f4-ae5c-793401a76653 fwd="216.198.98.78" dyno=web.1 connect=0ms service=10015ms status=503 bytes=0 protocol=https
2022-06-20T04:01:56.161890+00:00 heroku[web.1]: Process exited with status 1
2022-06-20T04:01:56.253251+00:00 heroku[web.1]: State changed from up to crashed
The entire code can be found here.
or here with omitted commented out code:
server.get('/:state/:classification/:className', async (req, res) => {
let className = req.params.className.replaceAll('-', ' ');
className = className.replaceAll('/', ' ');
const { url } = await classificationsModel.findOne(
{
name: className.toLowerCase(),
associatedState: req.params.state.toUpperCase(),
},
{ url: 1, _id: 0 }
);
console.log(url);
res.json('hello world');
teamList = [];
});
Again locally this is produced in the console and 'hello world' is returned as json. Why is it different on heroku and how can I fix it?

I'm trying to deploy my first MongoDB, Express, websockets app to Heroku and I can't get it to connect

**
I've added a Procfile, added ObjectRocket addon, and created a DB there
heres whats in the Procfile
**
```
web: node server.js
```
Here's whats in the .env file
*
```
ORMONGO_URL='mongodb://iad2-c13-0.mongo.objectrocket.com:53577'
ORMONGO_REGION=IAD
ORMONGO_RS_URL='mongodb://iad2-c13-0.mongo.objectrocket.com:53577,iad2-c13-
2.mongo.objectrocket.com:53577,iad2-c13-1.mongo.objectrocket.com:53577/?
replicaSet=5df3e347a4384bf8968b430ec021a64f'
PORT = 8000
```
Here's my server.js where I try to connect to the ObjectRocket addon database:
*
```
*
WEB/HTTP SERVER
*
```
const mongodb = require("mongodb");
const bodyParser = require("body-parser");
const session = require("express-session");
const MongoStore = require("connect-mongo")(session);
const path = require("path");
const express = require("express");
const app = express();
const MongoClient = require("mongodb").MongoClient;
```
Here I try to create the connection string
```
var username = "james";
var password = "websockets";
var hosts =
"iad2-c13-0.mongo.objectrocket.com:53577,iad2-c13-2.mongo.objectrocket.com:53577,iad2-c13-
1.mongo.objectrocket.com:53577";
var database = "websockets";
var options = "?replicaSet=5df3e347a4384bf8968b430ec021a64f";
var connectionString =
"mongodb://" +
username +
":" +
password +
"#" +
hosts +
"/" +
database +
options;
Here I set express for pug and files
app.use("/public", express.static(__dirname + "/public"));
app.set("view engine", "pug");
app.use(
bodyParser.urlencoded({
extended: true,
})
);
```
First attempt to connect to add user to DB
```
app.get("/", (request, response, next) => {
response.render("signup");
});
app.post("/signup", (request, response, next) => {
request.body.name;
request.body.email;
request.body.password;
mongodb.MongoClient.connect(connectionString, (error, client) => {
if (error) {
console.log(error);
response.redirect("/signup");
} else {
const db = client.db("websockets");
db.collection("users", (error, collection) => {
collection.insertOne(
{
name: request.body.name,
email: request.body.email,
password: request.body.password,
},
(error, result) => {
if (error) {
response.redirect("/signup");
}
}
);
});
response.redirect("/login");
}
});
});
```
heres the error log
PS C:\Users\James\Desktop\Atelier_back\pictionary_p5> heroku logs --tail
» Warning: heroku update available from 7.42.4 to 7.43.2.
2020-09-25T10:59:28.815676+00:00 heroku[router]: at=info method=GET path="/signup" host=evening-coast-84225.herokuapp.com request_id=ab3d1667-52ae-493b-b3a1-5d4849879b71 fwd="91.166.35.81" dyno=web.1 connect=0ms service=6ms status=200 bytes=723 protocol=https
2020-09-25T10:59:28.959611+00:00 heroku[router]: at=info method=GET path="/public/style.css" host=evening-coast-84225.herokuapp.com request_id=f4ae2a13-4c15-480b-b109-c177626ab743 fwd="91.166.35.81" dyno=web.1 connect=0ms service=17ms status=304 bytes=237 protocol=https
2020-09-25T10:59:30.952533+00:00 heroku[router]: at=info method=GET path="/login" host=evening-coast-84225.herokuapp.com request_id=35d8b3e2-544c-4aa1-b771-d2f5afc035a4 fwd="91.166.35.81" dyno=web.1 connect=0ms service=32ms status=200 bytes=648 protocol=https
2020-09-25T10:59:31.087075+00:00 heroku[router]: at=info method=GET path="/public/style.css" host=evening-coast-84225.herokuapp.com request_id=c57919a7-5e16-455c-95f9-96f791629a15 fwd="91.166.35.81" dyno=web.1 connect=0ms service=4ms status=304 bytes=237 protocol=https
2020-09-25T10:59:36.419574+00:00 heroku[router]: at=info method=POST path="/login" host=evening-coast-84225.herokuapp.com request_id=65bfc81e-84f9-4545-8922-05792448b74e fwd="91.166.35.81" dyno=web.1 connect=0ms service=127ms status=302 bytes=249 protocol=https
2020-09-25T10:59:36.524540+00:00 heroku[router]: at=info method=GET path="/login" host=evening-coast-84225.herokuapp.com request_id=89f6b294-f2e9-4b44-a95e-6142bad05433 fwd="91.166.35.81" dyno=web.1 connect=0ms service=2ms status=200 bytes=648 protocol=https
2020-09-25T10:59:36.651733+00:00 heroku[router]: at=info method=GET path="/public/style.css" host=evening-coast-84225.herokuapp.com request_id=6fc746f3-14bc-4d27-9b9c-6d669f582b62 fwd="91.166.35.81" dyno=web.1 connect=0ms service=2ms status=304 bytes=237 protocol=https
2020-09-25T10:59:51.074822+00:00 heroku[router]: at=info method=POST path="/login" host=evening-coast-84225.herokuapp.com request_id=497437d8-7f0e-4da5-9a4f-a646274a4c15 fwd="91.166.35.81" dyno=web.1 connect=1ms service=79ms status=302 bytes=249 protocol=https
2020-09-25T10:59:51.196106+00:00 heroku[router]: at=info method=GET path="/login" host=evening-coast-84225.herokuapp.com request_id=f3bb3025-06be-4cd0-9c36-c90b5ec8cb09 fwd="91.166.35.81" dyno=web.1 connect=1ms service=18ms status=200 bytes=648 protocol=https
2020-09-25T10:59:51.327253+00:00 heroku[router]: at=info method=GET path="/public/style.css" host=evening-coast-84225.herokuapp.com request_id=d1185dcb-eded-4314-b54b-783c03ddde2b fwd="91.166.35.81" dyno=web.1 connect=0ms service=5ms status=304 bytes=237 protocol=https
2020-09-25T11:00:01.409973+00:00 heroku[router]: at=info method=GET path="/signup" host=evening-coast-84225.herokuapp.com request_id=b4c79f5d-966a-4696-8bdd-4d32c6bb07f3 fwd="91.166.35.81" dyno=web.1 connect=0ms service=6ms status=304 bytes=151 protocol=https
2020-09-25T11:00:01.581572+00:00 heroku[router]: at=info method=GET path="/public/style.css" host=evening-coast-84225.herokuapp.com request_id=7e0cf022-3ddc-485e-99fb-0f8064f9dd24 fwd="91.166.35.81" dyno=web.1 connect=0ms service=32ms status=304 bytes=237 protocol=https
2020-09-25T11:00:08.832547+00:00 app[web.1]: MongoNetworkError: failed to connect to server [iad2-c13-2.mongo.objectrocket.com:53577] on first connect [MongoError: Authentication failed.
2020-09-25T11:00:08.832561+00:00 app[web.1]: at Connection.messageHandler (/app/node_modules/mongodb/lib/core/connection/connection.js:360:19)
2020-09-25T11:00:08.832563+00:00 app[web.1]: at Connection.emit (events.js:315:20)
2020-09-25T11:00:08.832564+00:00 app[web.1]: at processMessage (/app/node_modules/mongodb/lib/core/connection/connection.js:452:10)
2020-09-25T11:00:08.832564+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongodb/lib/core/connection/connection.js:621:15)
2020-09-25T11:00:08.832565+00:00 app[web.1]: at Socket.emit (events.js:315:20)
2020-09-25T11:00:08.832565+00:00 app[web.1]: at addChunk (_stream_readable.js:295:12)
2020-09-25T11:00:08.832567+00:00 app[web.1]: at readableAddChunk (_stream_readable.js:271:9)
2020-09-25T11:00:08.832567+00:00 app[web.1]: at Socket.Readable.push (_stream_readable.js:212:10)
2020-09-25T11:00:08.832568+00:00 app[web.1]: at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
2020-09-25T11:00:08.832569+00:00 app[web.1]: ok: 0,
2020-09-25T11:00:08.832570+00:00 app[web.1]: code: 18,
2020-09-25T11:00:08.832570+00:00 app[web.1]: codeName: 'AuthenticationFailed',
2020-09-25T11:00:08.832571+00:00 app[web.1]: operationTime: [Timestamp],
2020-09-25T11:00:08.832572+00:00 app[web.1]: '$clusterTime': [Object]
2020-09-25T11:00:08.832572+00:00 app[web.1]: }]
2020-09-25T11:00:08.832573+00:00 app[web.1]: at Pool.<anonymous> (/app/node_modules/mongodb/lib/core/topologies/server.js:438:11)
2020-09-25T11:00:08.832573+00:00 app[web.1]: at Pool.emit (events.js:315:20)
2020-09-25T11:00:08.832573+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/pool.js:562:14
2020-09-25T11:00:08.832574+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/pool.js:1009:9
2020-09-25T11:00:08.832574+00:00 app[web.1]: at callback (/app/node_modules/mongodb/lib/core/connection/connect.js:75:5)
2020-09-25T11:00:08.832575+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/connect.js:147:27
2020-09-25T11:00:08.832575+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/auth/scram.js:108:14
2020-09-25T11:00:08.832576+00:00 app[web.1]: at _callback (/app/node_modules/mongodb/lib/core/connection/connection.js:329:7)
2020-09-25T11:00:08.832576+00:00 app[web.1]: at Connection.messageHandler (/app/node_modules/mongodb/lib/core/connection/connection.js:360:9)
2020-09-25T11:00:08.832577+00:00 app[web.1]: at Connection.emit (events.js:315:20)
2020-09-25T11:00:08.835653+00:00 heroku[router]: at=info method=POST path="/signup" host=evening-coast-84225.herokuapp.com request_id=a1833b19-b344-4e98-90da-68135aad5b9a fwd="91.166.35.81" dyno=web.1 connect=0ms service=72ms status=302 bytes=252 protocol=https
2020-09-25T11:00:08.954095+00:00 heroku[router]: at=info method=GET path="/signup" host=evening-coast-84225.herokuapp.com request_id=e5dbd4b0-e3f3-4b09-9a39-ef82a692f476 fwd="91.166.35.81" dyno=web.1 connect=1ms service=8ms status=200 bytes=723 protocol=https
2020-09-25T11:00:09.082458+00:00 heroku[router]: at=info method=GET path="/public/style.css" host=evening-coast-84225.herokuapp.com request_id=4b237eb1-edee-4e09-86f5-9d6e3b725f17 fwd="91.166.35.81" dyno=web.1 connect=0ms service=3ms status=304 bytes=237 protocol=https
2020-09-25T11:00:10.261510+00:00 app[web.1]: MongoNetworkError: failed to connect to server [iad2-c13-1.mongo.objectrocket.com:53577] on first connect [MongoError: Authentication failed.
2020-09-25T11:00:10.261525+00:00 app[web.1]: at Connection.messageHandler (/app/node_modules/mongodb/lib/core/connection/connection.js:360:19)
2020-09-25T11:00:10.261525+00:00 app[web.1]: at Connection.emit (events.js:315:20)
2020-09-25T11:00:10.261526+00:00 app[web.1]: at processMessage (/app/node_modules/mongodb/lib/core/connection/connection.js:452:10)
2020-09-25T11:00:10.261527+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongodb/lib/core/connection/connection.js:621:15)
2020-09-25T11:00:10.261527+00:00 app[web.1]: at Socket.emit (events.js:315:20)
2020-09-25T11:00:10.261527+00:00 app[web.1]: at addChunk (_stream_readable.js:295:12)
2020-09-25T11:00:10.261528+00:00 app[web.1]: at readableAddChunk (_stream_readable.js:271:9)
2020-09-25T11:00:10.261528+00:00 app[web.1]: at Socket.Readable.push (_stream_readable.js:212:10)
2020-09-25T11:00:10.261529+00:00 app[web.1]: at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
2020-09-25T11:00:10.261530+00:00 app[web.1]: ok: 0,
2020-09-25T11:00:10.261531+00:00 app[web.1]: code: 18,
2020-09-25T11:00:10.261531+00:00 app[web.1]: codeName: 'AuthenticationFailed',
2020-09-25T11:00:10.261531+00:00 app[web.1]: operationTime: [Timestamp],
2020-09-25T11:00:10.261532+00:00 app[web.1]: '$clusterTime': [Object]
2020-09-25T11:00:10.261532+00:00 app[web.1]: }]
2020-09-25T11:00:10.261533+00:00 app[web.1]: at Pool.<anonymous> (/app/node_modules/mongodb/lib/core/topologies/server.js:438:11)
2020-09-25T11:00:10.261533+00:00 app[web.1]: at Pool.emit (events.js:315:20)
2020-09-25T11:00:10.261533+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/pool.js:562:14
2020-09-25T11:00:10.261534+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/pool.js:1009:9
2020-09-25T11:00:10.261534+00:00 app[web.1]: at callback (/app/node_modules/mongodb/lib/core/connection/connect.js:75:5)
2020-09-25T11:00:10.261535+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/connect.js:147:27
2020-09-25T11:00:10.261535+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/auth/scram.js:108:14
2020-09-25T11:00:10.261535+00:00 app[web.1]: at _callback (/app/node_modules/mongodb/lib/core/connection/connection.js:329:7)
2020-09-25T11:00:10.261536+00:00 app[web.1]: at Connection.messageHandler (/app/node_modules/mongodb/lib/core/connection/connection.js:360:9)
2020-09-25T11:00:10.261536+00:00 app[web.1]: at Connection.emit (events.js:315:20)
2020-09-25T11:00:10.264445+00:00 heroku[router]: at=info method=POST path="/signup" host=evening-coast-84225.herokuapp.com request_id=521aaf6d-7d63-4d15-8c8d-c3a8c8c1ea31 fwd="91.166.35.81" dyno=web.1 connect=2ms service=54ms status=302 bytes=252 protocol=https
2020-09-25T11:00:10.370377+00:00 heroku[router]: at=info method=GET path="/signup" host=evening-coast-84225.herokuapp.com request_id=e95baff4-d58c-479a-ab5c-95cd3163b72a fwd="91.166.35.81" dyno=web.1 connect=0ms service=4ms status=200 bytes=723 protocol=https
2020-09-25T11:00:10.502587+00:00 heroku[router]: at=info method=GET path="/public/style.css" host=evening-coast-84225.herokuapp.com request_id=1958ab4f-ccbf-4c86-a803-b9a75877acde fwd="91.166.35.81" dyno=web.1 connect=0ms service=6ms status=304 bytes=237 protocol=https
2020-09-25T11:00:11.181066+00:00 app[web.1]: MongoNetworkError: failed to connect to server [iad2-c13-1.mongo.objectrocket.com:53577] on first connect [MongoError: Authentication failed.
2020-09-25T11:00:11.181084+00:00 app[web.1]: at Connection.messageHandler (/app/node_modules/mongodb/lib/core/connection/connection.js:360:19)
2020-09-25T11:00:11.181086+00:00 app[web.1]: at Connection.emit (events.js:315:20)
2020-09-25T11:00:11.181088+00:00 app[web.1]: at processMessage (/app/node_modules/mongodb/lib/core/connection/connection.js:452:10)
2020-09-25T11:00:11.181089+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongodb/lib/core/connection/connection.js:621:15)
2020-09-25T11:00:11.181089+00:00 app[web.1]: at Socket.emit (events.js:315:20)
2020-09-25T11:00:11.181090+00:00 app[web.1]: at addChunk (_stream_readable.js:295:12)
2020-09-25T11:00:11.181091+00:00 app[web.1]: at readableAddChunk (_stream_readable.js:271:9)
2020-09-25T11:00:11.181091+00:00 app[web.1]: at Socket.Readable.push (_stream_readable.js:212:10)
2020-09-25T11:00:11.181092+00:00 app[web.1]: at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
2020-09-25T11:00:11.181093+00:00 app[web.1]: ok: 0,
2020-09-25T11:00:11.181094+00:00 app[web.1]: code: 18,
2020-09-25T11:00:11.181094+00:00 app[web.1]: codeName: 'AuthenticationFailed',
2020-09-25T11:00:11.181096+00:00 app[web.1]: operationTime: [Timestamp],
2020-09-25T11:00:11.181096+00:00 app[web.1]: '$clusterTime': [Object]
2020-09-25T11:00:11.181096+00:00 app[web.1]: }]
2020-09-25T11:00:11.181097+00:00 app[web.1]: at Pool.<anonymous> (/app/node_modules/mongodb/lib/core/topologies/server.js:438:11)
2020-09-25T11:00:11.181097+00:00 app[web.1]: at Pool.emit (events.js:315:20)
2020-09-25T11:00:11.181098+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/pool.js:562:14
2020-09-25T11:00:11.181098+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/pool.js:1009:9
2020-09-25T11:00:11.181098+00:00 app[web.1]: at callback (/app/node_modules/mongodb/lib/core/connection/connect.js:75:5)
2020-09-25T11:00:11.181099+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/connect.js:147:27
2020-09-25T11:00:11.181099+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/auth/scram.js:108:14
2020-09-25T11:00:11.181100+00:00 app[web.1]: at _callback (/app/node_modules/mongodb/lib/core/connection/connection.js:329:7)
2020-09-25T11:00:11.181100+00:00 app[web.1]: at Connection.messageHandler (/app/node_modules/mongodb/lib/core/connection/connection.js:360:9)
2020-09-25T11:00:11.181100+00:00 app[web.1]: at Connection.emit (events.js:315:20)
2020-09-25T11:00:11.181770+00:00 heroku[router]: at=info method=POST path="/signup" host=evening-coast-84225.herokuapp.com request_id=9d65540b-8132-416b-95f1-61cac24d4810 fwd="91.166.35.81" dyno=web.1 connect=0ms service=67ms status=302 bytes=252 protocol=https
2020-09-25T11:00:11.296931+00:00 heroku[router]: at=info method=GET path="/signup" host=evening-coast-84225.herokuapp.com request_id=c77ce66c-2d50-4906-ae85-f3e2309288df fwd="91.166.35.81" dyno=web.1 connect=0ms service=8ms status=200 bytes=723 protocol=https
2020-09-25T11:00:11.429086+00:00 heroku[router]: at=info method=GET path="/public/style.css" host=evening-coast-84225.herokuapp.com request_id=b131eaf2-e48e-462e-84d4-8f7b4d51aa1c fwd="91.166.35.81" dyno=web.1 connect=0ms service=3ms status=304 bytes=237 protocol=https
2020-09-25T11:00:13.161144+00:00 heroku[router]: at=info method=GET path="/public/style.css" host=evening-coast-84225.herokuapp.com request_id=b1ed0cde-00e7-4782-b32f-d04da727910f fwd="91.166.35.81" dyno=web.1 connect=1ms service=5ms status=304 bytes=237 protocol=https

Heroku Couldn't start my app.js (Code H10 status 503)

Let me start with screenshoots.
FULL ERROR LOG IS THERE
2020-06-15T10:46:45.640400+00:00 heroku[web.1]: Starting process with command `npm start`
2020-06-15T10:46:47.833544+00:00 app[web.1]:
2020-06-15T10:46:47.833563+00:00 app[web.1]: > learn-blog#1.0.0 start /app
2020-06-15T10:46:47.833563+00:00 app[web.1]: > node app.js
2020-06-15T10:46:47.833563+00:00 app[web.1]:
2020-06-15T10:47:22.069169+00:00 app[web.1]: MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
2020-06-15T10:47:22.069203+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:826:32)
2020-06-15T10:47:22.069204+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:335:15)
2020-06-15T10:47:22.069204+00:00 app[web.1]: at run (/app/app_server/server/server.js:26:20)
2020-06-15T10:47:22.069204+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:3:1)
2020-06-15T10:47:22.069205+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1138:30)
2020-06-15T10:47:22.069205+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
2020-06-15T10:47:22.069205+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:986:32)
2020-06-15T10:47:22.069205+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:879:14)
2020-06-15T10:47:22.069206+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
2020-06-15T10:47:22.069206+00:00 app[web.1]: at internal/main/run_main_module.js:17:47 {
2020-06-15T10:47:22.069207+00:00 app[web.1]: reason: TopologyDescription {
2020-06-15T10:47:22.069207+00:00 app[web.1]: type: 'ReplicaSetNoPrimary',
2020-06-15T10:47:22.069207+00:00 app[web.1]: setName: null,
2020-06-15T10:47:22.069207+00:00 app[web.1]: maxSetVersion: null,
2020-06-15T10:47:22.069207+00:00 app[web.1]: maxElectionId: null,
2020-06-15T10:47:22.069208+00:00 app[web.1]: servers: Map {
2020-06-15T10:47:22.069208+00:00 app[web.1]: 'learningcluster-shard-00-01-izdfm.mongodb.net:27017' => [ServerDescription],
2020-06-15T10:47:22.069208+00:00 app[web.1]: 'learningcluster-shard-00-02-izdfm.mongodb.net:27017' => [ServerDescription],
2020-06-15T10:47:22.069208+00:00 app[web.1]: 'learningcluster-shard-00-00-izdfm.mongodb.net:27017' => [ServerDescription]
2020-06-15T10:47:22.069209+00:00 app[web.1]: },
2020-06-15T10:47:22.069209+00:00 app[web.1]: stale: false,
2020-06-15T10:47:22.069209+00:00 app[web.1]: compatible: true,
2020-06-15T10:47:22.069210+00:00 app[web.1]: compatibilityError: null,
2020-06-15T10:47:22.069210+00:00 app[web.1]: logicalSessionTimeoutMinutes: null,
2020-06-15T10:47:22.069210+00:00 app[web.1]: heartbeatFrequencyMS: 10000,
2020-06-15T10:47:22.069210+00:00 app[web.1]: localThresholdMS: 15,
2020-06-15T10:47:22.069210+00:00 app[web.1]: commonWireVersion: null
2020-06-15T10:47:22.069211+00:00 app[web.1]: }
2020-06-15T10:47:22.069211+00:00 app[web.1]: }
2020-06-15T10:47:22.143281+00:00 heroku[web.1]: Process exited with status 0
2020-06-15T10:47:22.184007+00:00 heroku[web.1]: State changed from starting to crashed
2020-06-15T10:48:10.737182+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=morning-taiga-29926.herokuapp.com request_id=840ea8ca-9d88-451d-9720-77cbafc687c0 fwd="88.238.178.195" dyno= connect= service= status=503 bytes= protocol=https
2020-06-15T10:48:11.205261+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=morning-taiga-29926.herokuapp.com request_id=2f1efa47-f83b-4d52-8d1c-2a7e45e7b666 fwd="88.238.178.195" dyno= connect= service= status=503 bytes= protocol=https
I checked my mongodb atlas cluster and my ip address is in whitelist. Also, i tried to set network access to 0.0.0.0/0 but its didn't worked too...
By the way, everything is works perfectly in my local address (8080).
I fixed it.
I added this things in my code;
mongoose.Promise = global.Promise;
...
const PORT = process.env.PORT || 8080;
const CONNECTION_URI = process.env.MONGODB_URI || 'mongodb+srv://learnBlogAdmin:learnBlogAdminsPowsyetmiş22a#learningcluster-izdfm.mongodb.net/personalblog?retryWrites=true&w=majority';
...
run()
.then(() => {
console.log("IT WORKS");
})
.catch((err) => {
console.log(err);
throw err;
})
And its worked.

Categories

Resources