[英]nodemon not loading environment variables
以下是我的gulpfile.js
:
const nodemon = require('nodemon')
const server = nodemon({
script: './src/index.js',
ext: 'hbs json js css',
require: 'dotenv/config',
dotenv_config_path: './config/.env',
stdout: false // without this line the stdout event won't fire
})
我希望在package.json
文件中复制与dev
脚本完全相同的行为:
"scripts": {
"test": "jest --watch",
"dev": "nodemon -r dotenv/config ./src/index.js dotenv_config_path=./config/.env -e js,hbs,json,css",
"debug": "nodemon --inspect -r dotenv/config ./src/index.js dotenv_config_path=./config/.env -e js,hbs,json,css"
},
对于某种原因似乎gulp
不登记在定义的环境变量.env
文件。 虽然下面的行在使用npm run dev
时工作得很好:
nodemon -r dotenv/config ./src/index.js dotenv_config_path=./config/.env -e js,hbs,json,css
您可能需要将export
添加到您的环境变量并在运行nodemon
之前加载它们:
变量文件
export ENV_FIRST="J"
export ENV_LAST="Doe"
包.json
"scripts": {
"dev": "source vars.env; nodemon ..."
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.