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.
Related
I am facing
[nodemon] app crashed - waiting for file changes before starting...
While hosting my NodeJS Apollo GraphQL express server on Heroku.
It is also showing
2022-10-06T17:21:11.889722+00:00 app[web.1]: [nodemon] 2.0.20
2022-10-06T17:21:11.889912+00:00 app[web.1]: [nodemon] to restart at any time, enter `rs`
2022-10-06T17:21:11.890274+00:00 app[web.1]: [nodemon] watching path(s): *.*
2022-10-06T17:21:11.890314+00:00 app[web.1]: [nodemon] watching extensions: js,mjs,json
2022-10-06T17:21:11.890669+00:00 app[web.1]: [nodemon] starting `nodemon -r esm .`
2022-10-06T17:21:13.608667+00:00 app[web.1]: /app/node_modules/esm/esm.js:1
2022-10-06T17:21:13.616378+00:00 app[web.1]: const __global__ = this;(function (require, module, __shared__) { var __shared__;const
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
Here is my index.js
import express from "express";
import mongoose from "mongoose";
import { DB, mode } from "./config";
import { ApolloServer } from "apollo-server-express";
import AuthMiddleware from "./middlewares/auth";
import * as AppModels from "./models";
import { resolvers, typeDefs } from "./graphql";
const startServer = async () => {
const PORT = process.env.PORT || 3000;
try {
const app = express();
app.use(AuthMiddleware);
const apolloServer = new ApolloServer({
typeDefs,
resolvers,
playground: mode,
context: ({ req }) => {
let { isAuth, user } = req;
return { req, isAuth, user, ...AppModels };
},
});
mongoose.connect(DB, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
await apolloServer.start();
await apolloServer.applyMiddleware({ app });
app.listen({ port: PORT }, () =>
console.log(`Server started at port ${PORT}`,)
);
} catch (err) {
console.log("error: "+err);
}
};
startServer();
Here is my package.json
{
"name": "forefest-backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon -r esm .",
"server": "sudo systemctl start mongod && nodemon -r esm",
"dev": "nodemon -r esm"
},
"repository": {
"type": "git",
"url": "git+https://github.com/anshuman-8/forefest-backend.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/anshuman-8/forefest-backend/issues"
},
"homepage": "https://github.com/anshuman-8/forefest-backend#readme",
"dependencies": {
"apollo-server-express": "^3.10.2",
"bcryptjs": "^2.4.3",
"consola": "^2.15.3",
"dotenv": "^16.0.2",
"esm": "^3.2.25",
"express": "^4.18.1",
"graphql": "^16.6.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21",
"mongoose": "^6.6.1",
"mongoose-paginate-v2": "^1.7.1",
"nodemon": "^2.0.20",
"yup": "^0.32.11"
}
}
I have tried multiple ways of fixing this problem, Please help me.
This is my first time deploying a server.
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.
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
When I run npm start
My result is ..
> nodefirebase_curd#1.0.0 start
> nodemon index.js
[nodemon] 2.0.13
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
internal/modules/cjs/loader.js:905
throw err;
^
Error: Cannot find module 'cors'
Require stack:
- C:\Users\tong1\Desktop\test-Firebase\nodeFirebase_CURD\index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (C:\Users\tong1\Desktop\test-Firebase\nodeFirebase_CURD\index.js:3:14)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\tong1\\Desktop\\test-Firebase\\nodeFirebase_CURD\\index.js'
]
}
What wrong with this. I try to fix cors function but it doesn't work.
'use strict';
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const config = require('./config');
const studentRoutes = require('./routes/student-routes');
const app = express()
app.use(express.json());
app.use(cors());
app.use(bodyParser.json());
app.use('./api', studentRoutes.routes);
app.listen(config.port, () => console.log('App is listening on url http://localhost:' + config.port));
This is my package.json.
{
"name": "nodefirebase_curd",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"firebase": "^9.1.0",
"firebase-admin": "^9.12.0"
},
"devDependencies": {
"nodemon": "^2.0.13"
}
}
I'm struck in this problem with a long time.
Can you help me, please.
Thank you so much.
you don't have cors in dependencies
Install the dependency by npm i cors -P
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.