MySQL Forums
Forum List  »  Connector/Node.js

nodejs/ ERROR!!! HELP needed!
Posted by: Raymond Jender
Date: June 30, 2020 07:25AM

So I can successfully update a database using the following code in my node server:
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
database: "db",
user: "user",
password: "password"

con.connect(function(err) {
if (err) throw err;

And this code to do the update:

socket.on('data', (data) => {
console.log('roomid is = ', data);

var sql = "insert into `room` (`roomid`) values ('"+data+"');"
con.query(sql, function (err, result) {
if (err) throw err;
console.log("1 record inserted");

This works fine, however, at some point the following error occurs and the server shuts down. I have never withnessed the error as it happens when I am not working on my project. Probably late in the day or early hours of the morning?

throw er; // Unhandled 'error' event

Error: Connection lost: The server closed the connection.
at Protocol.end (/root/node_modules/mysql/lib/protocol/Protocol.js:112:13)
at Socket.<anonymous> (/root/node_modules/mysql/lib/Connection.js:94:28)
at Socket.<anonymous> (/root/node_modules/mysql/lib/Connection.js:526:10)
at Socket.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1224:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on Connection instance at:
at Connection._handleProtocolError (/root/node_modules/mysql/lib/Connection .js:423:8)
at Protocol.emit (events.js:315:20)
at Protocol._delegateError (/root/node_modules/mysql/lib/protocol/Protocol. js:398:10)
at Protocol.end (/root/node_modules/mysql/lib/protocol/Protocol.js:116:8)
at Socket.<anonymous> (/root/node_modules/mysql/lib/Connection.js:94:28)
[... lines matching original stack trace ...]
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
fatal: true,

Any ideas how to fix this?



Options: ReplyQuote

Written By
June 26, 2020 12:52PM
June 30, 2020 11:31AM
nodejs/ ERROR!!! HELP needed!
June 30, 2020 07:25AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.