What does connecting storage to my NextJS project do?

I have a NextJS project in Vercel. I also have a Postgres DB Storage in Vercel.

My Next app is able to connect to my DB because I added the DB’s connection details to the Next app’s environment variables.

I also notice that I can ‘connect’ my DB to my Next app in my app’s storage tab, where I can also select which environments of my app to make the DB available to.

What is the benefit of this connect feature? Would this be for connecting different DB’s to different staging environments?
If I only have a production environment and 1 DB what can this feature do for me?
Can I remove the environment variables from my Next app?
Just looking to understand if I can leverage this and the impact it will have on my setup.

Thanks! :slight_smile:

Hi, @nolanwit! Welcome to the Vercel Community :wave:

Yes, you can remove the database connection environment variables from your Next.js app when using Vercel’s Postgres connect feature . Here’s how it works:

  1. You remove manually set DB connection variables from your app
  2. Vercel injects necessary variables at runtime
  3. Your code still uses process.env.VARIABLE_NAME, but Vercel manages the values

You can definitely leverage this feature, and it will have several positive impacts on your setup:

  1. Simplifies secure database connections
  2. Automates credential management
  3. Enhances security by handling sensitive information
  4. Automates credential updates if they change

Even with just one production environment and one database, you’ll benefit from:

  1. Streamlined setup process
  2. Improved security measures
  3. Easier future scaling if you add more environments later

Does that help?

1 Like

Hi @pawlean,

That’s very helpful, and great to know!
Thank you for your detailed response!

Glad it was helpful, see you around the community :wave: