如何在更改文件时重新加载node.js? [英] How do I have foreman reload node.js when a file is changed?
问题描述
我目前使用主管在本地开发时运行我的node.js应用程序。这很好,但我现在将我的所有配置存储在 .bash_profile
,我想将它们移动到 .env
文件。
有没有办法使用主管的文件观看功能来获取领班的环境加载功能?
其中一种方法是将它添加到我的 Procfile
中,但我怀疑这会弄乱Heroku。
`local:supervisor web.js`
这是我放在一起的解决方案,效果很好。
安装重新运行和 Rb-fsevent 。
sudo gem install rerun rb-fsevent
如果您还没有安装Foreman。
sudo gem install foreman
将您的环境变量放在 .env
。
不要忘记添加 .env
到您的 .gitignore
,不想要敏感信息
echo'.env'>> .gitignore
这是我的 Procfile
的样子像
web:node web.js
现在就开始像这样
重新运行foreman start web
额外信贷,创建别名
echoalias rrun ='rerun foreman start web'>> 〜/ .bash_profile
I currently use supervisor to run my node.js app when developing locally. This has been great, but I currently store all my configs in my .bash_profile
, I want to move them to a .env
file.
Is there a way to get the environment loading features of foreman with the file watching features of supervisor?
One option is to add it to my Procfile
like this, but I suspect that will mess up Heroku.
`local: supervisor web.js`
This is the solution I put together and it works great.
Install Rerun and Rb-fsevent.
sudo gem install rerun rb-fsevent
Install Foreman if you have not already.
sudo gem install foreman
Put your environment variables in .env
in the root of your project.
Don't forget to add .env
to your .gitignore
, don't want that sensitive info in your code
echo '.env' >> .gitignore
Here is what my Procfile
looks like
web: node web.js
Now just start like this
rerun foreman start web
Extra Credit, create an alias
echo "alias rrun='rerun foreman start web'" >> ~/.bash_profile
这篇关于如何在更改文件时重新加载node.js?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!