config vs convict vs dotenv vs nconf
Node.js 設定管理ライブラリ
configconvictdotenvnconf類似パッケージ:

Node.js 設定管理ライブラリ

設定管理ライブラリは、アプリケーションの設定を効率的に管理し、環境に応じた設定を簡単に切り替えるためのツールです。これらのライブラリは、設定ファイルの読み込み、環境変数の管理、デフォルト値の設定などをサポートし、開発者がアプリケーションの設定を一元管理できるようにします。これにより、アプリケーションの移植性や保守性が向上します。

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

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
config06,426207 kB122ヶ月前MIT
convict02,37541.9 kB731ヶ月前Apache-2.0
dotenv020,410103 kB221日前BSD-2-Clause
nconf03,861162 kB1131年前MIT

機能比較: config vs convict vs dotenv vs nconf

設定の階層構造

  • config:

    configは、設定を階層的に管理できるため、異なる環境ごとに異なる設定を簡単に切り替えることができます。設定ファイルを複数持ち、環境ごとに異なる設定を自動的に読み込むことができます。

  • convict:

    convictは、設定のスキーマを定義することで、設定の階層構造を持つことができます。これにより、設定の整合性を保ちながら、異なる環境に応じた設定を管理できます。

  • dotenv:

    dotenvは、環境変数を使用するため、設定の階層構造は持ちませんが、シンプルに環境ごとの設定を管理できます。

  • nconf:

    nconfは、設定の階層構造を持ち、複数の設定ソースを組み合わせることができます。これにより、柔軟な設定管理が可能です。

バリデーション機能

  • config:

    configには、バリデーション機能はありませんが、設定ファイルの整合性を保つために、開発者が注意を払う必要があります。

  • convict:

    convictは、設定のスキーマを定義することで、設定値のバリデーションを行います。これにより、無効な設定を防ぎ、アプリケーションの信頼性を向上させます。

  • dotenv:

    dotenvは、バリデーション機能を持たず、環境変数の読み込みのみを行います。設定の整合性は開発者の責任です。

  • nconf:

    nconfは、バリデーション機能を持たず、設定の整合性は開発者が管理する必要があります。

使いやすさ

  • config:

    configは、設定ファイルの構造が明確で、使いやすいですが、複雑な設定が必要な場合には少し手間がかかることがあります。

  • convict:

    convictは、スキーマ定義が必要なため、初めて使う際には少し学習コストがありますが、設定の整合性を保つためには非常に便利です。

  • dotenv:

    dotenvは非常にシンプルで、環境変数を簡単に管理できるため、使いやすさは抜群です。

  • nconf:

    nconfは、設定ソースを柔軟に組み合わせることができるため、使い方に慣れるまで少し時間がかかるかもしれませんが、非常に強力です。

拡張性

  • config:

    configは、設定ファイルを追加することで拡張できますが、柔軟性には限界があります。

  • convict:

    convictは、スキーマを通じて設定を拡張できるため、非常に柔軟です。新しい設定項目を簡単に追加できます。

  • dotenv:

    dotenvは、環境変数を使用するため、拡張性は限られていますが、シンプルさを保つことができます。

  • nconf:

    nconfは、複数の設定ソースを柔軟に組み合わせることができるため、拡張性が高いです。

メンテナンス性

  • config:

    configは、設定ファイルが明確に分かれているため、メンテナンスが比較的容易です。

  • convict:

    convictは、スキーマを使用することで、設定の変更が明確になり、メンテナンス性が向上します。

  • dotenv:

    dotenvは、環境変数を直接管理するため、シンプルでメンテナンスが容易です。

  • nconf:

    nconfは、設定ソースを統合するため、メンテナンスが少し複雑になることがありますが、柔軟性が高いです。

選び方: config vs convict vs dotenv vs nconf

  • config:

    configは、複数の設定ファイルをサポートし、環境ごとに異なる設定を簡単に管理したい場合に適しています。特に、設定の階層構造を持つ大規模なアプリケーションに向いています。

  • convict:

    convictは、設定のスキーマを定義し、バリデーションを行いたい場合に最適です。設定の整合性を確保し、開発中に設定ミスを防ぎたい場合に選択してください。

  • dotenv:

    dotenvは、環境変数を簡単に管理したい場合に最適です。特に、開発環境での設定を簡素化したい場合に使用します。

  • nconf:

    nconfは、設定のソースを柔軟に組み合わせたい場合に適しています。複数の設定ソース(ファイル、環境変数、コマンドライン引数など)を統合して管理したい場合に選択してください。

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