Reference Environment Variables in your project.js

by Jan König on Sep 10, 2018

Learn how to use environment variables in your project.js file.

Introduction

The project.js is Jovo project configuration file that stores information like which platforms are used (alexaSkill, googleAction), including additional information like project IDs, endpoints, etc.

One of the useful features of the project.js is the ability to add stages to deploy your voice app to different environments (like local on your computer and dev on Lambda). Environment variables are a great way to define values that are directly linked to the current environment.

Referencing environment variables in your project can be helpful if you want to use the project.js as a generic template and then leave it to each environment how to set its values.

How to use env variables

You need to do two steps to use env variables in your project.js file:

Referencing env key

You can reference env variables in your project.js with process.env.key. For example, if you want to reference the Alexa Skill ID, you can do it like this:

Setting env values

For local development, you can use a .env file in your root project directory that could look like this:

If you're hosting your voice app on a service like AWS Lambda, you can define the environment variables there:

Staging environment variable in AWS Lambda

Learn more about config.js and staging here.

Use Cases

Environment variables can be especially helpful for local development (in a local stage) where every developer e.g. has their own Alexa Skill ID and uses their own ASK CLI profile to deploy it to the Amazon Developer Portal:

The initial .env file could then look like this:

A new jovo build and jovo deploy would then use the empty Skill ID to create a new Alexa Skill. If the developer then pastes the Skill ID into the .env file, it is always used to deploy the Skill in the local stage.


Jan König

Co-founder at Jovo

Comments and Questions

Any specific questions? Just drop them below or join the Jovo Community Forum.

Join Our Newsletter

Be the first to get our free tutorials, courses, and other resources for voice app developers.