Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在使用cloudant模块从NodeJ连接cloudant db时,我是否应该担心关闭db连接?_Node.js_Cloudant_Dbconnection - Fatal编程技术网

Node.js 在使用cloudant模块从NodeJ连接cloudant db时,我是否应该担心关闭db连接?

Node.js 在使用cloudant模块从NodeJ连接cloudant db时,我是否应该担心关闭db连接?,node.js,cloudant,dbconnection,Node.js,Cloudant,Dbconnection,我使用nodejs中的“cloudant”模块连接到cloudant(npm安装——保存cloudant)。下面是启动db连接变量然后使用它的代码 //instantiate a cloudant var with the cloudant url. The url has id, password in it. cloudant = require('cloudant')(dbCredentials.url); //set the middleware with the db name db

我使用nodejs中的“cloudant”模块连接到cloudant(npm安装——保存cloudant)。下面是启动db连接变量然后使用它的代码

//instantiate a cloudant var with the cloudant url. The url has id, password in it.
cloudant = require('cloudant')(dbCredentials.url);

//set the middleware with the db name
db = cloudant.use(dbCredentials.dbName);

//use the db variable to insert data into the db
function(req){

  db.insert({
     name:req.name,
     age:req.age
   },id,function(err,doc){
         ....
   });
};

我应该担心在使用db变量后关闭连接吗?这对我来说没有意义,因为我们这里没有使用任何连接池。对我来说,我们只是用端点、凭证和db名称实例化db变量。稍后我们将cloudant资源称为RESTAPI。我在这里有点困惑,不认为我们需要做任何密切的联系(这实际上意味着除了取消cloudant变量之外什么都没有)。请分享我的意见,无论我是对是错?提前感谢。

默认情况下,Cloudant库使用默认的Node.js连接池,因此它将遵守服务器的“保持活动”指令,但您无需担心。只要继续进行Cloudant库函数调用,库就会在需要时进行HTTP连接——必要时重用现有连接,在其他情况下创建新连接。

感谢Glynn的回答。这就解释了我在找什么。