Next.js Discord

Discord Forum

Postgres + Knex.js + Next.js w/o creating a new TCP connection to Postgres from every single GET

Unanswered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
How does one use Postgres + Knex.js + Next.js so that each HTTP request does not result in a new TCP handshake to Postgres from Next.js?

2 Replies

you need to cache the knex instance so when importing the module you aren't recreating the connection on every request. there is an example in the next.js repo for this: https://github.com/vercel/next.js/blob/canary/examples/with-knex/knex/index.js
Sun bearOP
thanks Rafael!