jshttps://www.npmjs.com/package/config
支持yml格式,需要下载 npm install js-yaml -S
$ 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
}
}
}
//使用
cross-env指定配置环境
npm install cross-env --save
const config = require('config');
package.json 中配置
"scripts": {
"prod": "cross-env NODE_ENV= production", //会使用production中的配置,合并default中的配置
},
jshttps://www.npmjs.com/package/dotenv
npm install dotenv cross-env --save
创建.env文件
require('dotenv').config()
console.log(process.env) // remove this after you've confirmed it is working
本文作者:薛祁
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!