问题
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`
回答1:
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
回答2:
Another solution is to create another Procfile file for your development environment with your current configuration:
# Procfile.dev
web: supervisor app.js
And start foreman
using that file
$ foreman start -f Procfile.dev
You can optionally exclude that file from your git repo
$ echo "Procfile.dev" >> .git/info/exclude
来源:https://stackoverflow.com/questions/13727961/how-do-i-have-foreman-reload-node-js-when-a-file-is-changed