Configuration settings are stored within a JSON object located inside the /config folder. You can add multiple config files here for each development environment that you're using.

Gravity ships with default and production config files to get you started.

Using this approach will automatically load the correct configuration file depending on your environment. For example, you can load your test Stripe settings in your local development environment and your live settings when running in production.

Use a filename that matches your NODE_ENV name to load that config file in that environment.

Importing The Config Files

To access the key-value pairs in the config file within your code, you first need to import the config file.

First, import the config package and then get the specific object you want from the config file.

const config = require('config');
const settings = config.get('stripe');

This will import the Stripe settings from the config file loaded in your current environment.

You should store sensitive items like passwords and secrets inside an environment variable instead of the config file.

Last updated