Skip to content

Setting up the environment variables

Yash Aryan edited this page Jun 14, 2022 · 3 revisions

Environment variables

The application needs some variables for proper functioning. It is pretty useless without it.

Adding environment variables

Create a file named .env.local in the root directory of the application. This file will contain important information for the application. The structure of the file is as follows:

NEXT_PUBLIC_PROD_ENV=
NEXT_PUBLIC_SERVER_URL=
NEXT_PUBLIC_EMAILJS_SERVICE_ID=
NEXT_PUBLIC_EMAILJS_TEMPLATE_ID=
NEXT_PUBLIC_EMAILJS_PUBLIC_KEY=

Refer: .env.example

Definition of the variables

  • NEXT_PUBLIC_PROD_ENV
    This is identify if the application is running in production mode, or development mode. If you are running your application on local system, you might wanna set it to dev, and for production, set it to production

  • NEXT_PUBLIC_SERVER_URL
    It is the URL of your server. If your server is running on the same system as your frontend app, the default value should be http://localhost:3002, otherwise, if your server is running on a different system, you could set it up as http://192.x.x.x or https://api.backend.com. Keep in mind that there is no trailing / in the value.

Setup for EmailJS. These variables are required for the contact page, and the application might fail if these are not provided. However, you an set these as "null" or any random value if you o not want that functionality

Note: You can keep two files named .env.development.local and .env.production.local in your folder. This way, while on production, the production one would automatically be selected, and while on development, the development. This is not a requirement, but a suggestion if you are constantly switching between production and development channels.