Environment Variables

Loading Environment Variables

Next.js has built-in support for loading environment variables from .env file into process.env.

An example .env:

ASSETLAYER_URL = "https://api.assetlayer.com/api/v1"
ASSETLAYER_APP_ID = "<your-assetlayer-app-id>"
ASSETLAYER_APP_SECRET = "<your-assetlayer-app-secret>"
URL = "http://localhost:3000"
NEXTAUTH_SECRET = "<your-nextauth-secret>"
ENCRYPTION_SECRET = "<your-encryption-secret>"
ENVIRONMENT="local"

You can generate a new .env locally which will also generate a random Next auth secret and encryption secret by running the following command:

npm run create-env

You will then need to go to your new .env file and paste in your Asset Layer app ID and app secret.

This loads process.env.ASSETLAYER_URL, process.env.ASSETLAYER_APP_ID, andprocess.env.ASSETLAYER_APP_SECRET into the Node.js environment automatically allowing you to use them in Next.js data fetching methods and API routes.

Setting Up Environment Variables on Netlify

In order for your Sample App to work properly once deployed, you need to setup the Environment Variables on the server.

Read more about environment variables here.

Last updated