Platform

Setting up Environment Variables on Parse

Introduction

In this guide, you will learn how to configure Environment variables.

Goal

  • Learn how to set and use Environment Variables page.

Prerequisites

There are no pre-requisites to read or edit this page.

Environment Variables

They are variables that describes your environment. While constants cannot be reassigned during the execution, an Environment Variables may change.

One of the most popular Environment Variable is PATH which contains path to the folders that might contain the executables.

In a few words, an environment variable consists of a name / value pair and any number can be created and available for reference at any given time.

Here at Back4App, this block looks like:

How to use it?

In this section, we are going to show you how to set an Environment Variable and use it on our Cloud Code.

First step, what you need to is to access Server Settings > Environment Variables > Settings and set environment variables using KEY=VALUE format. Please, put each variable in one line. Something like the example below:


1
NODE_ENV=PRODUCTION

To use it on your Cloud Code, you can test it following the guide below:

main.js

1
2
3
4
5
Parse.Cloud.define("getEnvironmentVariable", (request) => {
  const NODE_ENV = process.env.NODE_ENV;
  
  return `NODE_ENV = ${NODE_ENV}`
});

main.js

1
2
3
4
5
Parse.Cloud.define("getEnvironmentVariable", function(request, response) {
   var NODE_ENV = process.env.NODE_ENV;

   response.success(NODE_ENV);
});

In order to test it, you can use API Console to call this Cloud Code function and test it.