繁体   English   中英

nodemon 未加载环境变量

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM