How to close mySql query connection in nodejs

0

I am using raw mySql query for my development. I want to close the query connection after executing the query. What can I use as per my code?

My Connection Sample:

const Sequelize = require('sequelize')
const dotenv = require('dotenv');
dotenv.config();

const sequelize =
  new Sequelize(process.env.DBNAME, process.env.DBUSER, process.env.DBPASS,
    {
      host: process.env.HOST,
      port: process.env.HOST_PORT,
      dialect: 'mysql',
      operatorsAliases: 0,
      timezone: "+06:00",

      pool: {
        max: 5,
        min: 0,
        acquire: 30000,
        idle: 10000,
      }
    }
  )

module.exports = sequelize;

My Query sample:

const dbConnect = require('../database/db');

let getEmployeeData = 
      await dbConnect.query(
                  `Select * From employee where employeeId = '00001'`, 
                  {type: QueryTypes.SELECT});

return res.json({data: getEmployeeData});

Before return I want to close my query connection. As I am getting error "packets_out_of_order" after idle the connection in nodejs, so I decide to test by closing the connection.

Thanks in advance...

mysql mysql-connector node.js node-mysql
2021-11-24 05:31:50
1

0

You can try with

dbConnect.end();
2021-11-24 05:34:31

I got an error after using this. "(node:7976) UnhandledPromiseRejectionWarning: TypeError: dbConnect.end is not a function"
A.K.M. Arifur Rahman

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................