How to use nodemon with .env files?

后端 未结 11 1035
伪装坚强ぢ
伪装坚强ぢ 2020-12-09 02:37

I am using an .env file to hold environment variables for the server. This works if I run the server with foreman start. But it doesn\'t work with nodemon.

I would

11条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-09 02:54

    With recent versions of Node (since io.js 1.6), you can pass it the -r flag to require a module on start. This lets you directly load .env by using nodemon's --exec:

    nodemon --exec 'node -r dotenv/config'
    

    This requires the npm package dotenv to be installed.

提交回复
热议问题