Skip to content
On this page

Pre-release

You are looking at the website for the fully functional Feathers v5 (Dove) pre-release. Check out what's new, and please let us know about any issues or questions . The current v4 documentation can be found at crow.docs.feathersjs.com.

Custom Environment Variables

While node-config used for application configuration recommends to pass environment based configuration as a JSON string in a single NODE_CONFIG environment variable, it is also possible to use other environment variables via the config/custom-environment-variables.json file which looks like this by default:

json
{
  "port": {
    "__name": "PORT",
    "__format": "number"
  },
  "host": "HOSTNAME"
}
{
  "port": {
    "__name": "PORT",
    "__format": "number"
  },
  "host": "HOSTNAME"
}

This sets app.get('port') using the PORT environment variable (if it is available) parsing it as a number and app.get('host') from the HOSTNAME environment variable.

tip

See the node-config custom envrionment variable documentation for more information.

Dotenv

To add support for dotenv .env files run

npm install dotenv --save
npm install dotenv --save

And update src/app.ts as follows:

ts
// dotenv replaces all environmental variables from ~/.env in ~/config/custom-environment-variables.json
import * as dotenv from 'dotenv'
dotenv.config()

import configuration from '@feathersjs/configuration'
// dotenv replaces all environmental variables from ~/.env in ~/config/custom-environment-variables.json
import * as dotenv from 'dotenv'
dotenv.config()

import configuration from '@feathersjs/configuration'
// dotenv replaces all environmental variables from ~/.env in ~/config/custom-environment-variables.json
import * as dotenv from 'dotenv'
dotenv.config()

import configuration from '@feathersjs/configuration'
// dotenv replaces all environmental variables from ~/.env in ~/config/custom-environment-variables.json
import * as dotenv from 'dotenv'
dotenv.config()

import configuration from '@feathersjs/configuration'

important

dotenv.config() needs to run before import configuration from '@feathersjs/configuration'

Released under the MIT License.