config vs dotenv vs dotenv-expand vs dotenv-flow
環境設定管理ライブラリ
configdotenvdotenv-expanddotenv-flow類似パッケージ:

環境設定管理ライブラリ

環境設定管理ライブラリは、アプリケーションの設定情報を管理するためのツールです。これらのライブラリは、開発環境や本番環境における設定の管理を簡素化し、環境変数を扱うための便利な方法を提供します。これにより、アプリケーションの設定をコードから分離し、異なる環境での動作を柔軟に調整することが可能になります。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
config06,426207 kB122ヶ月前MIT
dotenv020,403103 kB217日前BSD-2-Clause
dotenv-expand01,05219 kB212日前BSD-2-Clause
dotenv-flow090160.3 kB82年前MIT

機能比較: config vs dotenv vs dotenv-expand vs dotenv-flow

設定管理

  • config:

    configは、JSONやYAML形式の設定ファイルを使用して、複数の環境の設定を一元管理します。デフォルト設定を持ち、環境ごとにオーバーライドが可能で、複雑な設定を簡潔に管理できます。

  • dotenv:

    dotenvは、.envファイルから環境変数を読み込むシンプルな方法を提供します。これにより、環境変数をコードにハードコーディングすることなく、簡単に設定を管理できます。

  • dotenv-expand:

    dotenv-expandは、dotenvと組み合わせて使用することで、環境変数の展開をサポートします。これにより、他の環境変数を参照することができ、より動的な設定が可能になります。

  • dotenv-flow:

    dotenv-flowは、複数の.envファイルを使用して、環境ごとの設定を自動的に読み込みます。これにより、開発・テスト・本番環境での設定を簡単に切り替えることができます。

柔軟性

  • config:

    configは、複数の設定ファイルをサポートし、環境ごとに異なる設定を簡単に管理できます。設定の階層構造を持ち、必要に応じて設定をオーバーライドすることができます。

  • dotenv:

    dotenvは、シンプルさを重視しており、基本的な環境変数の読み込みに特化しています。設定が少ないプロジェクトに最適です。

  • dotenv-expand:

    dotenv-expandは、環境変数の展開を可能にすることで、より複雑な設定を扱うことができます。これにより、他の変数を参照することができ、柔軟性が向上します。

  • dotenv-flow:

    dotenv-flowは、異なる環境ごとの設定を自動的に切り替えることができ、柔軟な環境管理を実現します。特に、開発・テスト・本番環境での設定が異なる場合に便利です。

使いやすさ

  • config:

    configは、設定ファイルの構造が明確で、複雑な設定もわかりやすく管理できますが、初期設定には少し手間がかかる場合があります。

  • dotenv:

    dotenvは、.envファイルを使ったシンプルなアプローチで、すぐに使い始めることができます。設定が少ない場合は特に使いやすいです。

  • dotenv-expand:

    dotenv-expandは、dotenvと組み合わせて使うことで、展開機能を簡単に追加できますが、最初の設定には少し学習が必要です。

  • dotenv-flow:

    dotenv-flowは、複数の.envファイルを管理するための便利な機能を提供しますが、設定が複雑になる場合があります。

拡張性

  • config:

    configは、設定ファイルをカスタマイズするための柔軟なオプションを提供し、必要に応じて拡張することができます。

  • dotenv:

    dotenvは、基本的な機能に特化しているため、拡張性は限定的ですが、シンプルなプロジェクトには最適です。

  • dotenv-expand:

    dotenv-expandは、dotenvの機能を拡張するためのライブラリであり、他の環境変数を参照する必要がある場合に便利です。

  • dotenv-flow:

    dotenv-flowは、複数の.envファイルを管理するための拡張機能を提供し、環境ごとの設定を簡単に切り替えることができます。

メンテナンス

  • config:

    configは、設定ファイルが明確に構造化されているため、メンテナンスが容易です。環境ごとの設定を一元管理できるため、変更があった場合も簡単に対応できます。

  • dotenv:

    dotenvは、シンプルな構造のため、メンテナンスが容易です。しかし、設定が増えると管理が難しくなる可能性があります。

  • dotenv-expand:

    dotenv-expandは、dotenvの機能を拡張するため、メンテナンスが少し複雑になる場合がありますが、展開機能が必要な場合には便利です。

  • dotenv-flow:

    dotenv-flowは、複数の.envファイルを管理するため、メンテナンスが少し複雑になる可能性がありますが、環境ごとの設定を簡単に切り替えることができる利点があります。

選び方: config vs dotenv vs dotenv-expand vs dotenv-flow

  • config:

    設定ファイルをJSONやYAML形式で管理したい場合や、複数の環境設定を一元管理したい場合に選択します。また、デフォルト設定を持ち、環境ごとのオーバーライドが必要な場合にも適しています。

  • dotenv:

    シンプルな環境変数の読み込みが必要な場合に選択します。特に、.envファイルから環境変数を簡単に読み込むことができ、開発環境での設定管理が容易になります。

  • dotenv-expand:

    環境変数の展開が必要な場合に選択します。特に、他の環境変数を参照する必要がある場合に便利です。dotenvと組み合わせて使用することで、より柔軟な設定が可能になります。

  • dotenv-flow:

    複数の.envファイルを環境ごとに管理したい場合に選択します。特定の環境に応じた設定を自動的に読み込むことができ、開発・テスト・本番環境での設定管理が容易になります。

config のREADME

Configure your Node.js Applications

npm package Downloads Issues

Release Notes

Introduction

Node-config organizes hierarchical configurations for your app deployments.

It lets you define a set of default parameters, and extend them for different deployment environments (development, qa, staging, production, etc.).

Configurations are stored in configuration files within your application, and can be overridden and extended by environment variables, command line parameters, or external sources.

This gives your application a consistent configuration interface shared among a growing list of npm modules also using node-config.

Project Guidelines

  • Simple - Get started fast
  • Powerful - For multi-node enterprise deployment
  • Flexible - Supporting multiple config file formats
  • Lightweight - Small file and memory footprint
  • Predictable - Well tested foundation for module and app developers

Quick Start

The following examples are in JSON format, but configurations can be in other file formats.

Install in your app directory, and edit the default config file.

$ npm install config
$ mkdir config
$ vi config/default.json
{
  // Customer module configs
  "Customer": {
    "dbConfig": {
      "host": "localhost",
      "port": 5984,
      "dbName": "customers"
    },
    "credit": {
      "initialLimit": 100,
      // Set low for development
      "initialDays": 1
    }
  }
}

Edit config overrides for production deployment:

 $ vi config/production.json
{
  "Customer": {
    "dbConfig": {
      "host": "prod-db-server"
    },
    "credit": {
      "initialDays": 30
    }
  }
}

Use configs in your code:

const config = require('config');
//...
const dbConfig = config.get('Customer.dbConfig');
db.connect(dbConfig, ...);

if (config.has('optionalFeature.detail')) {
  const detail = config.get('optionalFeature.detail');
  //...
}

config.get() will throw an exception for undefined keys to help catch typos and missing values. Use config.has() to test if a configuration value is defined.

Start your app server:

$ export NODE_ENV=production
$ node my-app.js

Running in this configuration, the port and dbName elements of dbConfig will come from the default.json file, and the host element will come from the production.json override file.

TypeScript

Type declarations are published under types/ and resolved via typesVersions. Subpath typings are included for config/async, config/defer, config/parser, config/raw, and config/lib/util in addition to the main config entrypoint.

Articles

Further Information

If you still don't see what you are looking for, here are some more resources to check:

Contributors

lorenwestjdmarshallmarkstosi­Moseselliotttfmdkitzman
jfelegeleachi­M2kjosxenyoleosuncinarthanzel
leonardovillelajeremy-daley-krsimon-scherzingerBadger­Badger­Badger­Badgernsaboviccunneen
Osterjourth507tiny-rac00neheikesfgheorgheroncli
superovenairdrummingfoolwmertensXadilla­Xinsidedsbert

License

May be freely distributed under the MIT license.

Copyright (c) 2010-2026 Loren West and other contributors