Generate and configure the .env file env-file

The .env is a special file that is not part of the sample module, but is important for use in your Adobe Developer App Builder application. This file contains secrets and other information. Avoid committing this file to any code repository.

Who is this video for?

  • Developers new to Adobe Commerce with limited experience using Adobe App Builder who wants to learn about the .env file.

Video content

  • Introduction to the .env file and its purpose
  • How to generate the .env file
  • How to append the file to add new secrets
  • Avoid committing this file because it contains sensitive information
Transcript
In this video, we’ll talk about the .env file. To be able to run the application locally, deploy changes to App Builder, the .env file should be configured correctly. This file contains the needed secrets to connect to the developer console, as well as the secrets to connect to third parties, such as Commerce Instance in the context of this sample app.
Start by generating the .env file, running the aio app use command. The command will prompt you to select your project, and workspace, and the organization you’re logged into. Once done, the .env file will be created with the needed secrets to connect to your project on App Builder. Append the file was the additional secrets. For example, by adding the commerce URL, consumer key and consumer secret, access token and token secret to connect to an Adobe Commerce instance, It’s important to keep in mind that this file is for local use only. Make sure not to commit this file to your repository to avoid security issues, publishing secrets by mistake. To deploy using GitHub for CI/CD purposes, App Builder provides a way to configure credentials based on the GitHub secrets of your repository. Details can be found in the App Builder documentation, accessing the link on the screen.

Code Sample

# Specify your secrets here
# The .env file must not be committed to source control
## Adobe I/O Runtime credentials
AIO_runtime_auth=abcd1234-aaa-bbb-ccc-12345:Abcdd12345asdfadsfadsfee2323232323232
AIO_runtime_namespace=12345-someworkspace-stage
AIO_runtime_apihost=https://adobeioruntime.net
## Adobe I/O Console service account credentials (JWT) Api Key
SERVICE_API_KEY=

# You can include some commerce OAUTH credentials too, our sample module will use this
#COMMERCE_BASE_URL=https://somecommercewebsite.com/
#COMMERCE_CONSUMER_KEY=abcebdme5bvafnemk0mdeeiyfq123
#COMMERCE_CONSUMER_SECRET=ffff86sqws3pss5hhuofiqgq4t04rrr11
#COMMERCE_ACCESS_TOKEN=gdddfccronj098r4m04zyq773s5o64
#COMMERCE_ACCESS_TOKEN_SECRET=ggg7nb19jhr5gi9jzfan9ggzipe8yrus

You can see these static values being used in the sample module in file actions/commerce.index.js.

        const oauth = getCommerceOauthClient(
            {
                url: params.COMMERCE_BASE_URL,
                consumerKey: params.COMMERCE_CONSUMER_KEY,
                consumerSecret: params.COMMERCE_CONSUMER_SECRET,
                accessToken: params.COMMERCE_ACCESS_TOKEN,
                accessTokenSecret: params.COMMERCE_ACCESS_TOKEN_SECRET
            },
            logger
        )
recommendation-more-help
3a5f7e19-f383-4af8-8983-d01154c1402f