How to set environment variable in a Nextjs App and when to use NEXT_PUBLIC prefix?

1 · Ram · July 11, 2024, 10:39 p.m.
Summary
Setting environment variables in a Next.js app is straightforward. Next.js supports loading environment variables from .env files. Here’s a step-by-step guide on how to set and use environment variables in your Next.js application: Step 1: Create Environment Files Create environment files in the root directory of your project. Commonly used files include: .env.local (for local development) .env.development (for development environment) .env.production (for production environment) Remember to n...