Home » Node.js

Creating a pool of connection in Node.js

In this article, we are going to learn how to create a pool of connection using Node.js server?
Submitted by Manu Jemini, on November 24, 2017

As we are all set with our connection in previous articles, now we are going to focus on creating a pool of connection, so that a single connection basically a single thread of connection can be used by more than one user.

Here, we can also set the number of user that can work on that single thread by setting the connection limit.

After all these things, Yes the quality of server is important but while testing the server with a few users we can create a pool and I know it does not makes the process immensely efficient to a certain level but it helps you to not to create a new thread for every new user for a certain limit.

Server file

//step-1
var mysql=require('mysql');
//step-2
var pool=mysql.createPool({
	//step-3
	connectionLimit: "100",
	host: "127.0.0.1",
	user: "root",
	password: "123",
	database: "friendcircle1"
});

Discussing above steps

  • Require MySQL module.
  • Creating a pool of connection by using mysql.createPool() method.
  • Set connection limit of 100

While using the connection of pool

Use pool.getConnection() method and release the connection after every usage.

Prerequisite/recommended:

If you have any query do comment.



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.