{"repo":"karlhorky/next-js-tricks","free":true,"listed":false,"github":"https://github.com/karlhorky/next-js-tricks","clone":"git clone https://github.com/karlhorky/next-js-tricks.git","description":"A collection of useful Next.js tricks","language":null,"stars":22,"topics":["nextjs"],"license":null,"category":"databases-storage","readme_excerpt":"Next.js Tricks A collection of useful Next.js tricks Avoid PostgreSQL connection slots Error with Development Server The Next.js dev server uses Fast Refresh to update the app in the browser when app code is changed, re-running the code to achieve this. If the code has stateful operations in it, including creation of a connection to a database (eg. PostgreSQL, MongoDB), then these stateful operations will be re-run. In the case of code which connects to a database, what this means is that every time the code is changed (or even every time the file is saved without changes), new database connections will be created and the old connections will not be closed: util/database.ts Since PostgreSQL has a maximum of 100 connections by default, these connections accumulating over time will lead to exhaustion of the available connection slots and the following error: This has been documented to happen in both the pages/ directory and the App Router: - pages/ directory: vercel/next.js#26427 (discussion) - App Router: vercel/next.js#45483 The current workaround to avoid the issue is to store the first database connection in a property of the Node.js globalThis object and prevent creation of any further connections if the property already exists: util/database.ts Check Next.js TypeScript Plugin Diagnostics in Terminal Next.js includes a custom TypeScript plugin for diagnostics such as missing types on metadata exports. However, the plugin diagnostics are not reported by tsc or a next CLI s","default_branch":null,"files":null,"tree":[],"storefront":"/r/karlhorky","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/karlhorky/next-js-tricks/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}