Skip to content
DMNO
🚧 DMNO is still in beta! Use with caution!
✨ If you've tried DMNO or looked through the docs, let us know what you think!

Multi-environment configuration

Overview

DMNO supports multiple environments out of the box. This allows you to define different configuration item values in each environments. For example: development, staging, and production.

Configuration

To define different configurations for different environments, you can use the switchByNodeEnv helper method. This method takes an object where the keys are the environment names and the values are the configuration item for each environment. As is implied by the name, the configuration item for the current environment is selected based on the value of the NODE_ENV environment variable.

import { switchByNodeEnv } from 'dmno';
export default defineDmnoService({
pick: [
'NODE_ENV',
],
schema: {
MY_CONFIG_ITEM: {
value: switchByNodeEnv({
_default: 'default value',
development: 'development value',
staging: 'staging value',
production: (ctx) => {
return ctx.val ? 'production value' : 'production value 2';
},
}),
},
},
});

You can define as many configuration items as you need using the switchByNodeEnv method.

Environment variables

To set the environment for your application, you can use the NODE_ENV environment variable. This variable is commonly set to development, staging, or production depending on the environment.

For example, to set the environment to production and do a production build, you could run:

Terminal window
NODE_ENV=production pnpm exec dmno run -- my-build-command-goes-here

This is especially useful when the value of NODE_ENV might not be what you would expect (we’re looking at your Netlify). For example, when running a build on a CI server, you might want to set the environment to production to ensure that the correct configuration values are used.

Other environments

You may have a different env var that you want to use to switch between values. For example, you might want to use APP_ENV instead of NODE_ENV. You can do this by passing the name of the env var you want to use as the first argument to switchBy.

import { switchBy } from 'dmno';
export default defineDmnoService({
pick: [
'APP_ENV',
],
schema: {
MY_CONFIG_ITEM: {
value: switchBy('APP_ENV', {
_default: 'default value',
development: 'development value',
staging: 'staging value',
production: 'production value',
}),
},
},
});