[英]nodemon not loading environment variables
The following is in my gulpfile.js
:以下是我的
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
})
I am looking to duplicate the exact same behavior as the dev
script in the package.json
file:我希望在
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"
},
For one reason or another it seems that gulp
is not registering the environment variables defined in the .env
file.对于某种原因似乎
gulp
不登记在定义的环境变量.env
文件。 Although the line below works just fine when ran with npm run dev
:虽然下面的行在使用
npm run dev
时工作得很好:
nodemon -r dotenv/config ./src/index.js dotenv_config_path=./config/.env -e js,hbs,json,css
You may need to add export
to your environment vars and load them before running nodemon
:您可能需要将
export
添加到您的环境变量并在运行nodemon
之前加载它们:
vars.env变量文件
export ENV_FIRST="J"
export ENV_LAST="Doe"
package.json包.json
"scripts": {
"dev": "source vars.env; nodemon ..."
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.