You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Nodemon中-r参数功能咨询:开发环境重载env相关疑问

Understanding the -r Parameter in Your Nodemon Command

Great question! Let’s clear up the confusion here—you’re right not to find mention of -r in nodemon’s docs, because it’s not a nodemon-specific parameter at all! It belongs to Node.js itself, and nodemon just passes it through to the underlying Node process when starting your app.

Here’s a straightforward breakdown of how it works:

  • The -r flag (short for --require) is a Node.js command-line option that tells Node to load a specified module before executing your main application file.
  • In your command nodemon -r dotenv/config bin/www.js, nodemon triggers a Node process that first loads the dotenv/config module, then runs your bin/www.js file.
  • The dotenv/config module’s core job is to read your .env file and inject those environment variables into process.env. Since nodemon restarts the Node process whenever files change, this means your updated environment variables get reloaded automatically on each restart—exactly the behavior you’re seeing work!

To confirm this is Node.js logic, not nodemon’s, you could run the same environment variable setup without nodemon using:

node -r dotenv/config bin/www.js

Nodemon just adds the file-watching and auto-restart functionality on top of this native Node.js behavior.

内容的提问来源于stack exchange,提问作者tonywei

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 10:38:09