Environment Variables

By default, Next.js compiler looks for .env file in projects root folder and reads its content. In the project files you'll find a file .env.example that contains all the environment variables that were used in the app environment. The Sample App will not authenticate with Handcash or load information from your Asset Layer app.

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_SECRET = "<your-assetlayer-app-secret>"
HANDCASH_APP_ID = "<your-handcash-app-id>"
HANDCASH_APP_SECRET = "<your-handcash-app-secret>"
NEXTAUTH_SECRET = "<your-secret>"
ENVIRONMENT="local"

You can generate a new .env locally which will also generate a random 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 HandCash and Asset Layer App IDs and App Secrets.

This loads process.env.ASSETLAYER_URL, process.env.ASSETLAYER_APP_SECRET, process.env.HANDCASH_APP_ID, process.env.HANDCASH_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