Closed robinvdvleuten closed 6 years ago
That doesn't sound right -- connecting every time adds a ton of overhead compared to even a shared active connection, let alone a proper connection pool. And the examples in the official node-pg docs have a module (db/index.js
) caching a connection pool and exposing a query
function for the routes.
Application routes can be hit by many users simultaneously. Generally you want them to be as light as possible, which means doing your init outside as much as possible.
I am trying out Massive in my Express application and was wondering when to connect to the database. I've used the PG library before and they explicitly tell to connect within the routes. Is this also the case for Massive?