Managing Environment Variables

One of the key benefits of integrating your service with ShipEngine Connect is that we will handle the hosting of your application for you. In order for us to do that, ShipEngine Connect may need access to sensitive data, such as the credentials used to connect to your backend service.

You may securely provide such information using the connect env command. This command allows you to define environment variables at the time your application is published that will be injected into your application when it is running in ShipEngine Connect.

In addition to storing application secrets, environment variables are useful for storing your configuration data, such as the URL for your backend API, so that you can easily switch between environments without making any changes to your application. This is one of the tenets of The Twelve-Factor App, which we highly recommend considering when planning your application.

Using the CLI

The ShipEngine Connect CLI provides an env command with several subcommands that help you manage the environment variables available within your application.

Setting Environment Variables

The connect env:set subcommand is used to set one or more environment variables.

Example

This example shows running the connect env:set command and its output.

$ connect env:set MY_VARIABLE=foo my_second_variable=bar
MY_VARIABLE=foo has been set.
MY_SECOND_VARIABLE=bar has been set.

Getting Specific Environment Variables

The connect env:get subcommand is used get the value of one or more environment variables. This is useful when you have a lot of environment variables to be able to get the value of the variable(s) of interest.

Example

This example shows running the connect env:get command for the MY_VARIABLE environment variable.

$ connect env:get my_second_variable
┌─────────────┬───────┐
│ Name │ Value │
├─────────────┼───────┤
│ MY_VARIABLE │ foo │
└─────────────┴───────┘

Removing an Unwanted Environment Variable

The connect env:unset command is used to unset one or more environment variables. After running this command, the specified environment variable will no longer be set the next time you publish your app.

Example

This example shows running the connect env:unset command and its output.

$ connect env:unset my_second_variable
MY_VARIABLE has been removed as an environment variable.

Listing Environment Variables

The connect env:list command is used to list all the environment variables that are set along with their values.

Example

This example shows running the connect env:list command and its default output.

$ connect env:list
┌────────────────────┬─────────┐
│ Name │ Value │
├────────────────────┼─────────┤
│ MY_SECOND_VARIABLE │ bar │
├────────────────────┼─────────┤
│ MY_VARIABLE │ foo │
└────────────────────┴─────────┘

You can use the --format option to list environment variables in table format or in a format for easy use with dotenv.

Example

This example shows running the connect env:list command using the --format option (-f for short), specifying the dotenv format.

$ connect env:list -f dotenv
MY_SECOND_VARIABLE=bar
MY_VARIABLE=foo

Accessing Environment Variable

It is easy to access environment variables from within your Node.js application by using the process.env property that is available out-of-the-box with Node.js.

Example

This examples shows how to access an environment variable from within your ShipEngine Connect application.

console.log(`MY_VARIABLE is: ${process.env.MY_VARIABLE}`);