This package has been deprecated

Author message:

disabling package

TypeScript icon, indicating that this package has built-in type declarations

2.6.0 • Public • Published


The philosophy which inspire this package is configuration as code. With it you can create configuration classes to set up your express application, your database connection or others packages. Besides that, config-as-code uses nconf, enabling the use of enviroment files and access to process.env variables.


$ npm install --save config-as-code


Let's take an express configuration. Create the configuration module first:

import { ConfigModule, OnInitConfig } from 'config-as-code';

export class ExpressConfigModule implements OnInitConfig {
  init(app: Express) {

The string passed to the decorator is the module ID, which should be unique and easy to type, because it will be used later.

Now, let's create the application configurator:

import { Configurator, AbstractConfigurator } from 'config-as-code';
import { ExpressConfigModule } from './express.config';

import * as express from 'express';

  configModules: [ ExpressConfigModule ],
  enviromentFilesPath: 'configuration/enviroments'
export class ApplicationConfigurator extends AbstractConfigurator {}

In this, you first set the Configurator decorator, which defines:

  1. configModules: this sets which configuration modules will be executed and in which order.
  2. enviromentFilesPath: the path, relative to the root of the project, to the enviroments folder.

This class implements the AbstractConfigurator that provides behavior for initializing the application and receive an object in which the key should be the configuration module ID and the value an array that will be passed to the init method in configuration module. Additionally, you can pass parameters with the __all ID, which will be passed to every configuration module.

Then, in your startup scprit (e.g. index.ts, server.ts):

import { ApplicationConfigurator } from 'config-as-code';
const config = new ApplicationConfigurator();
  express: [ app ],
  __all: [ "Application name" ]


Using nconf, you are able to use enviroment files for development, test and production. By default, the package will look for this files in the enviroments subfolder inside the project root folder.


The Variables store is an interface to the nconf package, allowing access to variables from:

  • process.env
  • enviroment file
  • defaults (the only default variable set is NODE_ENV as development, and it is override if is set in process.env)
  • memory

However, it is only possible to set variables in the memory store, to maintaing consistency in the others stores and to allow objects to be saved.

P.S.: the first three stores will only have data after the application been initalized through Configurator.

The use is simples:

import { Variables } from 'config-as-code';

Variables.set('message', 'Hello World');

// By default: development

// Hello World


Feel free to add them.


  • Create Variables class to expose nconf memory store, which support both key/value and object store.
  • Support to set the enviroments file location.
  • Add option to use a json file instead of an array to define load sequence.
  • Enable to config modules to be called individually, allowing more flexibilty on the order where configuration code should run.

Package Sidebar


npm i config-as-code

Weekly Downloads






Last publish


  • caiorcferreira