Zbynek Zbynek - 10 months ago 67
MySQL Question

NodeJS + mysql - automatically closing pool connections?

I wish to use connection pooling using NodeJS with MySQL database. According to docs, there are two ways to do that: either I explicitly get connection from the pool, use it and release it:

var pool = require('mysql').createPool(opts);

pool.getConnection(function(err, conn) {
conn.query('select 1+1', function(err, res) {

Or I can use it like this:

var mysql = require('mysql');
var pool = mysql.createPool({opts});

pool.query('select 1+1', function(err, rows, fields) {
if (err) throw err;

console.log('The solution is: ', rows[0].solution);

If I use the second options, does that mean, that connections are automatically pulled from the pool, used and released? And if so, is there reason to use the first approach?

Answer Source


follow this it may help you......................