Код:
var sql = require("mysql");
var connection = sql.createConnection({
host: 'localhost',
user: 'root',
password: 'password',
database: 'chat'
});
app.get('/', function(req, res) {
connection.connect();
var loga = "kulonful";
connection.query('select * from users where login = "'+loga+'"', function(err, result){
if(err) { connection.end(); res.send('Произошла критическая ошибка'); }
connection.end();
res.send(result);
});
})
В первый раз всё гладенько, а если обновить страницу - в консоли выбивает ошибку:
events.js:160
throw er; // Unhandled 'error' event
^
Error: Cannot enqueue Handshake after invoking quit.
at Protocol._validateEnqueue (/root/node_modules/mysql/lib/protocol/Protocol.js:202:16)
at Protocol._enqueue (/root/node_modules/mysql/lib/protocol/Protocol.js:135:13)
at Protocol.handshake (/root/node_modules/mysql/lib/protocol/Protocol.js:52:41)
at Connection.connect (/root/node_modules/mysql/lib/Connection.js:130:18)
at /root/api.js:18:16
at Layer.handle [as handle_request] (/root/node_modules/express/lib/router/layer.js:82:5)
at next (/root/node_modules/express/lib/router/route.js:100:13)
at Route.dispatch (/root/node_modules/express/lib/router/route.js:81:3)
at Layer.handle [as handle_request] (/root/node_modules/express/lib/router/layer.js:82:5)
at /root/node_modules/express/lib/router/index.js:235:24
Что не так? Помогите)