S
S
s_katala2018-04-17 12:22:50
MySQL
s_katala, 2018-04-17 12:22:50

How to fix Connection lost: The server closed the connection error?

After 40 seconds, the connection is disconnected and displays an error

(node:10832) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
events.js:183
      throw er; // Unhandled 'error' event
      ^
Error: Connection lost: The server closed the connection.
    at Protocol.end (C:\Users\sskat\Desktop\project\node_modules\mysql\lib\protocol\Protocol.js:113:13)
    at Socket.<anonymous> (C:\Users\sskat\Desktop\project\node_modules\mysql\lib\Connection.js:109:28)
    at emitNone (events.js:111:20)
    at Socket.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1055:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

Here is the file
const
  mysql = require('mysql'),
  { error } = require('handy-log'),
  { MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE } = process.env
const db = mysql.createConnection({
  host: MYSQL_HOST,
  user: MYSQL_USER,
  password: MYSQL_PASSWORD,
  database: MYSQL_DATABASE,
  charset: 'utf8mb4'
})
db.connect(err => {
  if(err){
    error(err.message)
  }
})
module.exports = db

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
eternalSt, 2018-04-17
@eternalSt

Good time!
Check out this thread , it's the same problem.
And in general, google gives out a lot of things on request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question