Need Assistance?

support@tutorialshub.in

Middleware, Auth & Security

Environment Variables (Server vs Public)

ADVERTISEMENT
Next.js Free Lesson
5 min read
ADVERTISEMENT

Next.js loads .env.local automatically. To keep your secrets safe, Next.js follows one strict rule:

  • Variables without a prefix (like DATABASE_URL or STRIPE_SECRET_KEY) are only available on the server.
  • Variables starting with NEXT_PUBLIC_ (like NEXT_PUBLIC_SITE_URL) are bundled into browser JavaScript—never put private keys there!
ADVERTISEMENT
Hi, I'm Tuby! Here to help you