user6064424
user6064424

Reputation:

When should one use connection pooling in node.js mysql?

This is the typical way I create MySQL connection in node.js

var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : '',
  database : 'address_book'
});
var app = express();

connection.connect(function(err){
if(!err) {
    console.log("Database is connected ... nn");    
} else {
    console.log("Error connecting database ... nn");    
}
});

Is it good enough for production use? When should one use connection pooling? What are the advantages and disadvantages of using connection pooling?

Upvotes: 3

Views: 1038

Answers (1)

Somil
Somil

Reputation: 587

This will work but creating mysql connection for each and every request is not recommended.

So it would be better to have a pool of mysql connections, as cost of getting a connection will be nil compared to prior case.

Upvotes: 1

Related Questions