I have created a Node API using MySQL and deployed it on Heroku. But after every 20-25 minutes it shows 'Application error' and I have to do 'Heroku restart' again to fetch data from API. My API calls work fine when runs on localhost:port_no
Heroku Logs
>2021-06-26T04:15:47.965652+00:00 heroku[web.1]: State changed from starting to up
2021-06-26T04:20:47.759660+00:00 app[web.1]: events.js:353
2021-06-26T04:20:47.759669+00:00 app[web.1]: throw er; // Unhandled 'error' event
2021-06-26T04:20:47.759670+00:00 app[web.1]: ^
2021-06-26T04:20:47.759670+00:00 app[web.1]:
2021-06-26T04:20:47.759670+00:00 app[web.1]: Error: Connection lost: The server closed the connection.
2021-06-26T04:20:47.759671+00:00 app[web.1]: at Protocol.end (/app/node_modules/mysql/lib/protocol/Protocol.js:112:13)
2021-06-26T04:20:47.759672+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:94:28)
2021-06-26T04:20:47.759672+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:526:10)
2021-06-26T04:20:47.759673+00:00 app[web.1]: at Socket.emit (events.js:388:22)
2021-06-26T04:20:47.759673+00:00 app[web.1]: at endReadableNT (internal/streams/readable.js:1336:12)
2021-06-26T04:20:47.759674+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:82:21)
2021-06-26T04:20:47.759674+00:00 app[web.1]: Emitted 'error' event on Connection instance at:
2021-06-26T04:20:47.759676+00:00 app[web.1]: at Connection._handleProtocolError (/app/node_modules/mysql/lib/Connection.js:423:8)
2021-06-26T04:20:47.759677+00:00 app[web.1]: at Protocol.emit (events.js:376:20)
2021-06-26T04:20:47.759678+00:00 app[web.1]: at Protocol._delegateError (/app/node_modules/mysql/lib/protocol/Protocol.js:398:10)
2021-06-26T04:20:47.759678+00:00 app[web.1]: at Protocol.end (/app/node_modules/mysql/lib/protocol/Protocol.js:116:8)
2021-06-26T04:20:47.759679+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:94:28)
2021-06-26T04:20:47.759679+00:00 app[web.1]: [... lines matching original stack trace ...]
2021-06-26T04:20:47.759679+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:82:21) {
2021-06-26T04:20:47.759680+00:00 app[web.1]: fatal: true,
2021-06-26T04:20:47.759680+00:00 app[web.1]: code: 'PROTOCOL_CONNECTION_LOST'
2021-06-26T04:20:47.759681+00:00 app[web.1]: }
2021-06-26T04:20:47.817878+00:00 heroku[web.1]: Process exited with status 1
2021-06-26T04:20:47.876488+00:00 heroku[web.1]: State changed from up to crashed
My connection.js file
const mysql = require('mysql');
var sqlConnection = mysql.createConnection({
host: ##,
user:##,
password: ##,
database: ##,
multipleStatements: true
});
sqlConnection.connect((err) => {
if (!err) {
console.log("Connected");
} else {
console.log("Connection Failed");
}
})
module.exports = sqlConnection;
```
Related
React beginner here. I just deployed an early-alpha of an app and currently getting this error -111 which from this site says that its a problem that occurs when mysqld only listens to the localhost interface. I'm using a free remote mysql for testing from this site. It says that I have to find my.cnf and modify it to allow connections aside from localhost.
Will it work if I edit my my.cnf or no because I'm using a free remote mysql that I have no control of?
Will it work if I try another free remote mysql service that may work differently?
2022-05-04T06:22:09.121413+00:00 app[web.1]: Error: connect ECONNREFUSED 127.0.0.1:3306
2022-05-04T06:22:09.121421+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16)
2022-05-04T06:22:09.121421+00:00 app[web.1]: --------------------
2022-05-04T06:22:09.121422+00:00 app[web.1]: at Protocol._enqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:144:48)
2022-05-04T06:22:09.121422+00:00 app[web.1]: at Protocol.handshake (/app/node_modules/mysql/lib/protocol/Protocol.js:51:23)
2022-05-04T06:22:09.121423+00:00 app[web.1]: at PoolConnection.connect (/app/node_modules/mysql/lib/Connection.js:116:18)
2022-05-04T06:22:09.121423+00:00 app[web.1]: at Pool.getConnection (/app/node_modules/mysql/lib/Pool.js:48:16)
2022-05-04T06:22:09.121424+00:00 app[web.1]: at Pool.query (/app/node_modules/mysql/lib/Pool.js:202:8)
2022-05-04T06:22:09.121424+00:00 app[web.1]: at /app/routes/operations/login.js:27:24
2022-05-04T06:22:09.121424+00:00 app[web.1]: at new Promise (<anonymous>)
2022-05-04T06:22:09.121425+00:00 app[web.1]: at getInput (/app/routes/operations/login.js:20:16)
2022-05-04T06:22:09.121425+00:00 app[web.1]: at /app/routes/operations/login.js:106:28
2022-05-04T06:22:09.121425+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5) {
2022-05-04T06:22:09.121426+00:00 app[web.1]: errno: -111,
2022-05-04T06:22:09.121426+00:00 app[web.1]: code: 'ECONNREFUSED',
2022-05-04T06:22:09.121427+00:00 app[web.1]: syscall: 'connect',
2022-05-04T06:22:09.121427+00:00 app[web.1]: address: '127.0.0.1',
2022-05-04T06:22:09.121427+00:00 app[web.1]: port: 3306,
2022-05-04T06:22:09.121427+00:00 app[web.1]: fatal: true
2022-05-04T06:22:09.121428+00:00 app[web.1]: }
My application works correctly in Localhost with following connection details:
const mysql = require("mysql");
var mysqlConnection = mysql.createConnection({
host: "gatorxxxx.hostgator.com",
user: "ermaulik_chdb",
password: "<password>",
database: "ermaulik_chdb",
port: <port>
})
mysqlConnection.connect((err) => {
if(!err) {
console.log("Connection")
} else {
console.log(err)
}
});
But, it doesn't work when I host this application on Heroku and throws following exception.
Just to give more context, my database in hosted in cpanel of hostgator.
2020-05-23T16:47:32.542824+00:00 app[web.1]: server is running on port: 54806
2020-05-23T16:47:32.812651+00:00 app[web.1]: Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'ermaulik_chdb'#'ec2-3-84-45-11.compute-1.amazonaws.com' (using password: YES)
2020-05-23T16:47:32.812658+00:00 app[web.1]: at Handshake.Sequence._packetToError (/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
2020-05-23T16:47:32.812659+00:00 app[web.1]: at Handshake.ErrorPacket (/app/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18)
2020-05-23T16:47:32.812659+00:00 app[web.1]: at Protocol._parsePacket (/app/node_modules/mysql/lib/protocol/Protocol.js:291:23)
2020-05-23T16:47:32.812660+00:00 app[web.1]: at Parser._parsePacket (/app/node_modules/mysql/lib/protocol/Parser.js:433:10)
2020-05-23T16:47:32.812661+00:00 app[web.1]: at Parser.write (/app/node_modules/mysql/lib/protocol/Parser.js:43:10)
2020-05-23T16:47:32.812661+00:00 app[web.1]: at Protocol.write (/app/node_modules/mysql/lib/protocol/Protocol.js:38:16)
2020-05-23T16:47:32.812662+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:88:28)
2020-05-23T16:47:32.812662+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:526:10)
2020-05-23T16:47:32.812662+00:00 app[web.1]: at Socket.emit (events.js:310:20)
2020-05-23T16:47:32.812663+00:00 app[web.1]: at addChunk (_stream_readable.js:286:12)
2020-05-23T16:47:32.812663+00:00 app[web.1]: --------------------
2020-05-23T16:47:32.812664+00:00 app[web.1]: at Protocol._enqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:144:48)
2020-05-23T16:47:32.812664+00:00 app[web.1]: at Protocol.handshake (/app/node_modules/mysql/lib/protocol/Protocol.js:51:23)
2020-05-23T16:47:32.812665+00:00 app[web.1]: at Connection.connect (/app/node_modules/mysql/lib/Connection.js:116:18)
2020-05-23T16:47:32.812665+00:00 app[web.1]: at Object.<anonymous> (/app/connection.js:11:17)
2020-05-23T16:47:32.812666+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1133:30)
2020-05-23T16:47:32.812666+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
2020-05-23T16:47:32.812666+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:977:32)
2020-05-23T16:47:32.812667+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:877:14)
2020-05-23T16:47:32.812667+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1019:19)
2020-05-23T16:47:32.812667+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:77:18) {
2020-05-23T16:47:32.812668+00:00 app[web.1]: code: 'ER_ACCESS_DENIED_ERROR',
2020-05-23T16:47:32.812668+00:00 app[web.1]: errno: 1045,
2020-05-23T16:47:32.812669+00:00 app[web.1]: sqlMessage: "Access denied for user 'ermaulik_chdb'#'ec2-3-84-45-11.compute-1.amazonaws.com' (using password: YES)",
2020-05-23T16:47:32.812669+00:00 app[web.1]: sqlState: '28000',
2020-05-23T16:47:32.812669+00:00 app[web.1]: fatal: true
2020-05-23T16:47:32.812670+00:00 app[web.1]: }
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'ermaulik_chdb'#'ec2-3-84-45-11.compute-1.amazonaws.com'
you got an Error. because your MySQL database connection is Not Established.
Firstly, please check the Installed LAMP, Nodejs Acc. to your Code version supported. in the Heroku server. properly.
In the second step, check the MYSQL DB GRANT PRIVILEGES.
SHOW GRANTS FOR 'root'#'localhost';
the Third one is to Make sure your Nodejs Code & MySql DB
in the same server. If not you need to allow permission a server to connect OutSide the server.
and make sure the host, username, password, HOST all things are correct. I hope these things help you resolve a problem. thanks :)
This is the Heroku logs tail:
remote: https://desolate-temple-28640.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/desolate-temple-28640.git
132ab25..24b7d35 master -> master
Bilals-MacBook-Air:Eat-the-burger bilalsarimeseli$ heroku logs --tail
2020-03-05T04:29:51.676106+00:00 app[web.1]:
2020-03-05T04:29:51.676125+00:00 app[web.1]: > burger#1.0.0 start /app
2020-03-05T04:29:51.676125+00:00 app[web.1]: > node server.js
2020-03-05T04:29:51.676125+00:00 app[web.1]:
2020-03-05T04:29:51.929460+00:00 app[web.1]: Server listening on: http://localhost:5967
2020-03-05T04:29:51.932815+00:00 app[web.1]: error connecting: Error: connect ECONNREFUSED 127.0.0.1:3306
2020-03-05T04:29:51.932816+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16)
2020-03-05T04:29:51.932817+00:00 app[web.1]: --------------------
2020-03-05T04:29:51.932817+00:00 app[web.1]: at Protocol._enqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:144:48)
2020-03-05T04:29:51.932817+00:00 app[web.1]: at Protocol.handshake (/app/node_modules/mysql/lib/protocol/Protocol.js:51:23)
2020-03-05T04:29:51.932818+00:00 app[web.1]: at Connection.connect (/app/node_modules/mysql/lib/Connection.js:119:18)
2020-03-05T04:29:51.932818+00:00 app[web.1]: at Object. (/app/config/connection.js:16:12)
2020-03-05T04:29:51.932818+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1158:30)
2020-03-05T04:29:51.932819+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
2020-03-05T04:29:51.932819+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:1002:32)
2020-03-05T04:29:51.932819+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:901:14)
2020-03-05T04:29:51.932819+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1044:19)
2020-03-05T04:29:51.932820+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:77:18)
2020-03-05T04:29:53.272983+00:00 heroku[web.1]: State changed from starting to up
2020-03-05T05:04:18.124007+00:00 heroku[web.1]: Idling
2020-03-05T05:04:18.127663+00:00 heroku[web.1]: State changed from up to down
2020-03-05T05:04:18.993332+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-03-05T05:04:19.070341+00:00 heroku[web.1]: Process exited with status 143
2020-03-05T11:10:26.000000+00:00 app[api]: Build started by user bilalsarimeseli#gmail.com
2020-03-05T11:10:40.838353+00:00 heroku[web.1]: State changed from down to starting
2020-03-05T11:10:40.648875+00:00 app[api]: Deploy 24b7d357 by user bilalsarimeseli#gmail.com
2020-03-05T11:10:42.830384+00:00 heroku[web.1]: Starting process with command `npm start`
2020-03-05T11:10:40.648875+00:00 app[api]: Release v10 created by user bilalsarimeseli#gmail.com
2020-03-05T11:10:41.000000+00:00 app[api]: Build succeeded
2020-03-05T11:10:44.751738+00:00 app[web.1]:
2020-03-05T11:10:44.751800+00:00 app[web.1]: > burger#1.0.0 start /app
2020-03-05T11:10:44.751801+00:00 app[web.1]: > node server.js
2020-03-05T11:10:44.751806+00:00 app[web.1]:
2020-03-05T11:10:44.985822+00:00 app[web.1]: Server listening on: http://localhost:58632
2020-03-05T11:10:44.989700+00:00 app[web.1]: error connecting: Error: connect ECONNREFUSED 127.0.0.1:3306
2020-03-05T11:10:44.989705+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16)
2020-03-05T11:10:44.989706+00:00 app[web.1]: --------------------
2020-03-05T11:10:44.989709+00:00 app[web.1]: at Protocol._enqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:144:48)
2020-03-05T11:10:44.989710+00:00 app[web.1]: at Protocol.handshake (/app/node_modules/mysql/lib/protocol/Protocol.js:51:23)
2020-03-05T11:10:44.989710+00:00 app[web.1]: at Connection.connect (/app/node_modules/mysql/lib/Connection.js:119:18)
2020-03-05T11:10:44.989710+00:00 app[web.1]: at Object. (/app/config/connection.js:16:12)
2020-03-05T11:10:44.989710+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1158:30)
2020-03-05T11:10:44.989711+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
2020-03-05T11:10:44.989711+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:1002:32)
2020-03-05T11:10:44.989711+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:901:14)
2020-03-05T11:10:44.989711+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1044:19)
2020-03-05T11:10:44.989712+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:77:18)
2020-03-05T11:10:45.456540+00:00 heroku[web.1]: State changed from starting to up
2020-03-05T11:11:02.583806+00:00 app[web.1]: /app/config/orm.js:41
2020-03-05T11:11:02.583841+00:00 app[web.1]: throw err;
2020-03-05T11:11:02.583841+00:00 app[web.1]: ^
2020-03-05T11:11:02.583843+00:00 app[web.1]:
2020-03-05T11:11:02.583845+00:00 app[web.1]: Error: Cannot enqueue Query after fatal error.
2020-03-05T11:11:02.583846+00:00 app[web.1]: at Protocol._validateEnqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:212:16)
2020-03-05T11:11:02.583846+00:00 app[web.1]: at Protocol._enqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:138:13)
2020-03-05T11:11:02.583848+00:00 app[web.1]: at Connection.query (/app/node_modules/mysql/lib/Connection.js:201:25)
2020-03-05T11:11:02.583848+00:00 app[web.1]: at Object.selectAll (/app/config/orm.js:39:20)
2020-03-05T11:11:02.583849+00:00 app[web.1]: at Object.selectAll (/app/models/burger.js:7:13)
2020-03-05T11:11:02.583849+00:00 app[web.1]: at /app/controller/burgers_controller.js:10:12
2020-03-05T11:11:02.583849+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2020-03-05T11:11:02.583850+00:00 app[web.1]: at next (/app/node_modules/express/lib/router/route.js:137:13)
2020-03-05T11:11:02.583850+00:00 app[web.1]: at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
2020-03-05T11:11:02.583850+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5) {
2020-03-05T11:11:02.583851+00:00 app[web.1]: code: 'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR',
2020-03-05T11:11:02.583851+00:00 app[web.1]: fatal: false
2020-03-05T11:11:02.583851+00:00 app[web.1]: }
2020-03-05T11:11:02.591344+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-03-05T11:11:02.591569+00:00 app[web.1]: npm ERR! errno 1
2020-03-05T11:11:02.592540+00:00 app[web.1]: npm ERR! burger#1.0.0 start: `node server.js`
2020-03-05T11:11:02.592651+00:00 app[web.1]: npm ERR! Exit status 1
2020-03-05T11:11:02.592779+00:00 app[web.1]: npm ERR!
2020-03-05T11:11:02.592869+00:00 app[web.1]: npm ERR! Failed at the burger#1.0.0 start script.
2020-03-05T11:11:02.592974+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-03-05T11:11:02.596948+00:00 app[web.1]:
2020-03-05T11:11:02.597121+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-03-05T11:11:02.597200+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-03-05T11_11_02_593Z-debug.log
2020-03-05T11:11:02.659995+00:00 heroku[web.1]: State changed from up to crashed
2020-03-05T11:11:02.663569+00:00 heroku[web.1]: State changed from crashed to starting
2020-03-05T11:11:02.591268+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/" host=desolate-temple-28640.herokuapp.com request_id=babd3c58-db4a-4333-8b8c-1d3b6c180144 fwd="73.170.10.17" dyno=web.1 connect=1ms service=15ms status=503 bytes=0 protocol=https
2020-03-05T11:11:02.640946+00:00 heroku[web.1]: Process exited with status 1
2020-03-05T11:11:04.780991+00:00 heroku[web.1]: Starting process with command `npm start`
2020-03-05T11:11:06.928183+00:00 app[web.1]:
2020-03-05T11:11:06.928199+00:00 app[web.1]: > burger#1.0.0 start /app
2020-03-05T11:11:06.928199+00:00 app[web.1]: > node server.js
2020-03-05T11:11:06.928200+00:00 app[web.1]:
2020-03-05T11:11:07.188672+00:00 app[web.1]: Server listening on: http://localhost:23612
2020-03-05T11:11:07.192422+00:00 app[web.1]: error connecting: Error: connect ECONNREFUSED 127.0.0.1:3306
2020-03-05T11:11:07.192422+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16)
2020-03-05T11:11:07.192423+00:00 app[web.1]: --------------------
2020-03-05T11:11:07.192423+00:00 app[web.1]: at Protocol._enqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:144:48)
2020-03-05T11:11:07.192424+00:00 app[web.1]: at Protocol.handshake (/app/node_modules/mysql/lib/protocol/Protocol.js:51:23)
2020-03-05T11:11:07.192424+00:00 app[web.1]: at Connection.connect (/app/node_modules/mysql/lib/Connection.js:119:18)
2020-03-05T11:11:07.192424+00:00 app[web.1]: at Object. (/app/config/connection.js:16:12)
2020-03-05T11:11:07.192425+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1158:30)
2020-03-05T11:11:07.192425+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
2020-03-05T11:11:07.192425+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:1002:32)
2020-03-05T11:11:07.192426+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:901:14)
2020-03-05T11:11:07.192426+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1044:19)
2020-03-05T11:11:07.192426+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:77:18)
2020-03-05T11:11:07.594141+00:00 heroku[web.1]: State changed from starting to up
2020-03-05T11:15:26.050243+00:00 app[web.1]: /app/config/orm.js:41
2020-03-05T11:15:26.050267+00:00 app[web.1]: throw err;
2020-03-05T11:15:26.050267+00:00 app[web.1]: ^
2020-03-05T11:15:26.050268+00:00 app[web.1]:
2020-03-05T11:15:26.050270+00:00 app[web.1]: Error: Cannot enqueue Query after fatal error.
2020-03-05T11:15:26.050272+00:00 app[web.1]: at Protocol._validateEnqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:212:16)
2020-03-05T11:15:26.050272+00:00 app[web.1]: at Protocol._enqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:138:13)
2020-03-05T11:15:26.050273+00:00 app[web.1]: at Connection.query (/app/node_modules/mysql/lib/Connection.js:201:25)
2020-03-05T11:15:26.050274+00:00 app[web.1]: at Object.selectAll (/app/config/orm.js:39:20)
2020-03-05T11:15:26.050274+00:00 app[web.1]: at Object.selectAll (/app/models/burger.js:7:13)
2020-03-05T11:15:26.050275+00:00 app[web.1]: at /app/controller/burgers_controller.js:10:12
2020-03-05T11:15:26.050275+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2020-03-05T11:15:26.050275+00:00 app[web.1]: at next (/app/node_modules/express/lib/router/route.js:137:13)
2020-03-05T11:15:26.050276+00:00 app[web.1]: at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
2020-03-05T11:15:26.050276+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5) {
2020-03-05T11:15:26.050277+00:00 app[web.1]: code: 'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR',
2020-03-05T11:15:26.050277+00:00 app[web.1]: fatal: false
2020-03-05T11:15:26.050277+00:00 app[web.1]: }
2020-03-05T11:15:26.059015+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-03-05T11:15:26.059397+00:00 app[web.1]: npm ERR! errno 1
2020-03-05T11:15:26.061003+00:00 app[web.1]: npm ERR! burger#1.0.0 start: `node server.js`
2020-03-05T11:15:26.061232+00:00 app[web.1]: npm ERR! Exit status 1
2020-03-05T11:15:26.061464+00:00 app[web.1]: npm ERR!
2020-03-05T11:15:26.061676+00:00 app[web.1]: npm ERR! Failed at the burger#1.0.0 start script.
2020-03-05T11:15:26.061857+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-03-05T11:15:26.069984+00:00 app[web.1]:
2020-03-05T11:15:26.070271+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-03-05T11:15:26.070400+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-03-05T11_15_26_062Z-debug.log
2020-03-05T11:15:26.165120+00:00 heroku[web.1]: State changed from up to crashed
2020-03-05T11:15:26.144397+00:00 heroku[web.1]: Process exited with status 1
2020-03-05T11:15:26.058348+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/" host=desolate-temple-28640.herokuapp.com request_id=bba9be1c-a0a8-4187-9854-8f1adb4aef14 fwd="73.170.10.17" dyno=web.1 connect=0ms service=18ms status=503 bytes=0 protocol=https
2020-03-05T04:29:51.929460+00:00 app[web.1]: Server listening on: http://localhost:5967
2020-03-05T04:29:51.932815+00:00 app[web.1]: error connecting: Error: connect ECONNREFUSED 127.0.0.1:3306
I assume that you did bind your port to the environment variable $PORT which was supplied by Heroku. I assume that port is the 5967. Your program is trying to access 3306. You probably defined this port somewhere. This is on Heroku not possible.
Heroku only allows you to bind to a single port with the port number decided by Heroku.
2020-03-05T04:29:51.929460+00:00 app[web.1]: Server listening on: http://localhost:5967
2020-03-05T04:29:51.932815+00:00 app[web.1]: error connecting: Error: connect ECONNREFUSED 127.0.0.1:3306
You got an Error. Because your server tries to connect a 3306 PORT
But in your server Listening to a port 5967. simple change a PORT Number in own code .env file. Define a like
E.g.HOST=5967 in the .env file
const Sequelize = require('sequelize');
const sequelize = new Sequelize(`${process.env.SQL_DB}`, 'root', `${process.env.SQL_Password}`, {
dialect: 'mysql',
host: 'localhost'
});
module.exports = sequelize;
although I stored my config var in heroku settings but it can not connect with my database I think
errors
Unhandled rejection SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306
2020-01-07T10:27:38.586244+00:00 app[web.1]: at /app/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:139:19
2020-01-07T10:27:38.586246+00:00 app[web.1]: at tryCatcher (/app/node_modules/bluebird/js/release/util.js:16:23)
2020-01-07T10:27:38.586248+00:00 app[web.1]: at Promise._settlePromiseFromHandler (/app/node_modules/bluebird/js/release/promise.js:547:31)
2020-01-07T10:27:38.586250+00:00 app[web.1]: at Promise._settlePromise (/app/node_modules/bluebird/js/release/promise.js:604:18)
2020-01-07T10:27:38.586252+00:00 app[web.1]: at Promise._settlePromise0 (/app/node_modules/bluebird/js/release/promise.js:649:10)
2020-01-07T10:27:38.586254+00:00 app[web.1]: at Promise._settlePromises (/app/node_modules/bluebird/js/release/promise.js:725:18)
2020-01-07T10:27:38.586256+00:00 app[web.1]: at _drainQueueStep (/app/node_modules/bluebird/js/release/async.js:93:12)
2020-01-07T10:27:38.586258+00:00 app[web.1]: at _drainQueue (/app/node_modules/bluebird/js/release/async.js:86:9)
2020-01-07T10:27:38.586260+00:00 app[web.1]: at Async._drainQueues (/app/node_modules/bluebird/js/release/async.js:102:5)
2020-01-07T10:27:38.586262+00:00 app[web.1]: at Immediate.Async.drainQueues [as _onImmediate] (/app/node_modules/bluebird/js/release/async.js:15:14)
2020-01-07T10:27:38.586264+00:00 app[web.1]: at processImmediate (internal/timers.js:439:21)
i have deployed a nodejs app on heroku with ClearDb mysql, the app works for a few moments then crashes. i checked logs and got this errors
2019-09-20T19:03:41.536452+00:00 app[web.1]: events.js:174
2019-09-20T19:03:41.536474+00:00 app[web.1]: throw er; // Unhandled 'error' event
2019-09-20T19:03:41.536476+00:00 app[web.1]: ^
2019-09-20T19:03:41.536478+00:00 app[web.1]:
2019-09-20T19:03:41.536481+00:00 app[web.1]: Error: Connection lost: The server closed the connection.
2019-09-20T19:03:41.536483+00:00 app[web.1]: at Protocol.end (/app/node_modules/mysql/lib/protocol/Protocol.js:112:13)
2019-09-20T19:03:41.536485+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:97:28)
2019-09-20T19:03:41.536488+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:525:10)
2019-09-20T19:03:41.53649+00:00 app[web.1]: at Socket.emit (events.js:203:15)
2019-09-20T19:03:41.536492+00:00 app[web.1]: at endReadableNT (_stream_readable.js:1145:12)
2019-09-20T19:03:41.536495+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:63:19)
2019-09-20T19:03:41.536497+00:00 app[web.1]: Emitted 'error' event at:
2019-09-20T19:03:41.536503+00:00 app[web.1]: at Connection._handleProtocolError (/app/node_modules/mysql/lib/Connection.js:426:8)
2019-09-20T19:03:41.536506+00:00 app[web.1]: at Protocol.emit (events.js:198:13)
2019-09-20T19:03:41.536509+00:00 app[web.1]: at Protocol._delegateError (/app/node_modules/mysql/lib/protocol/Protocol.js:398:10)
2019-09-20T19:03:41.536511+00:00 app[web.1]: at Protocol.end (/app/node_modules/mysql/lib/protocol/Protocol.js:116:8)
2019-09-20T19:03:41.536513+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:97:28)
2019-09-20T19:03:41.536515+00:00 app[web.1]: [... lines matching original stack trace ...]
2019-09-20T19:03:41.536517+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:63:19)
2019-09-20T19:03:41.599727+00:00 heroku[web.1]: Process exited with status 1
2019-09-20T19:03:41.653368+00:00 heroku[web.1]: State changed from up to crashed
This could be the problem
You can use the following code to handle the server disconnect
var db_config = {
host: 'localhost',
user: 'root',
password: '',
database: 'example'
};
var connection;
function handleDisconnect() {
connection = mysql.createConnection(db_config); // Recreate the connection, since
// the old one cannot be reused.
connection.connect(function(err) { // The server is either down
if(err) { // or restarting (takes a while sometimes).
console.log('error when connecting to db:', err);
setTimeout(handleDisconnect, 2000); // We introduce a delay before attempting to reconnect,
} // to avoid a hot loop, and to allow our node script to
}); // process asynchronous requests in the meantime.
// If you're also serving http, display a 503 error.
connection.on('error', function(err) {
console.log('db error', err);
if(err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually
handleDisconnect(); // lost due to either server restart, or a
} else { // connnection idle timeout (the wait_timeout
throw err; // server variable configures this)
}
});
}
handleDisconnect();