ADVERTISEMENT
ADVERTISEMENT

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.

ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.