Movatterモバイル変換


[0]ホーム

URL:


config
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/config package

3.3.12 • Public • Published

NPM  Build Status  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 inconfiguration files within your application, and can be overridden and extended byenvironment variables,command line parameters, orexternal sources.

This gives your application a consistent configuration interface shared among agrowing 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 otherfile 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:

constconfig=require('config');//...constdbConfig=config.get('Customer.dbConfig');db.connect(dbConfig, ...);if(config.has('optionalFeature.detail')){constdetail=config.get('optionalFeature.detail');//...}

config.get() will throw an exception for undefined keys to help catch typos and missing values.Useconfig.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, theport anddbName elements ofdbConfigwill come from thedefault.json file, and thehost element willcome from theproduction.json override file.

Articles

Further Information

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

Contributors

lorenwestmarkstosiMoseselliotttfjfelegeleachiM2k
josxenyoleosuncinarthanzeleheikesth507
OsterjourcunneennsabovicBadgerBadgerBadgerBadgersimon-scherzingerleonardovillela
axelhzfbenkroegerfgheorgheIvanVergilievjpwilliamsjaylynch
jberrischkgoerlitzbertho-zeroNguyenMatthieunitzan-shakedrobertrossmann

License

May be freely distributed under theMIT license.

Copyright (c) 2010-2022 Loren Westand other contributors

Package Sidebar

Install

npm i config

Weekly Downloads

1,372,697

Version

3.3.12

License

MIT

Unpacked Size

94.4 kB

Total Files

9

Last publish

Collaborators

  • markstos
  • lorenwest

[8]ページ先頭

©2009-2025 Movatter.jp