Best Practice to Open/Close MongoDB Connection in Node.js Web App?

Showing 1-2 of 2 messages
Best Practice to Open/Close MongoDB Connection in Node.js Web App? David Graf 7/7/11 11:05 PM
Hello

What is the best practice to open and close a MongoDB connection in a node.js web app? Currently, I am opening the connection and I am starting the webserver in the corresponding callback function:

  db.open(function(err, db) {
    http.createServer(onRequest).listen(8888);
    console.log("Server has started.");
  }); 

Is this best practice? And where should I close the connection? Is closing the connection not necessary?

Best
David
Re: Best Practice to Open/Close MongoDB Connection in Node.js Web App? Callum Macrae 7/7/11 11:43 PM
That is absolutely fine. You don't need to close any connections anywhere.

Callum Macrae