Skip to main content

Environment Variables

Certain server features requires environment variables to be set. Please read the guides below to and set the variables that apply to you.

COLLAB_KEY#

Required to be set when using username and password authentication, or when signing in anonymous users. This is used as the key to encode JWT tokens for users. It can be set to any string.

How to set environment variables#

There are a few different ways you can set environment variables.

dotenv#

The easiest and most flexible way is using the dotenv NPM package.

First, create a .env file next to your server root and add your environment variables to it like so:

COLLAB_KEY=My_sUper_SEcreT_k3y

Then, at the top of your server file, import the dotenv package and call the config function.

require('dotenv').config();

Command line#

You can also set your environment variables via the command line on Mac and Linux.

If you are using windows, you can use the cross-env package to make this work.

Simply add the env variable before your server execution script. Commonly this is done in the package.json scripts section.

Mac and Linux:

{
"scripts": {
"start": "COLLAB_KEY=My_sUper_SEcreT_k3y node server.js"
}
}

Windows:

{
"scripts": {
"start": "cross-env COLLAB_KEY=My_sUper_SEcreT_k3y node server.js"
}
}