Can I tell foreman to reload the web app every time a request is made so I can develop decently?

user142019 picture user142019 · Feb 3, 2012 · Viewed 7.4k times · Source

A web app I am writing in JavaScript using node.js. I use Foreman, but I don't want to manually restart the server every time I change my code. Can I tell Foreman to reload the entire web app before handling an HTTP request (i.e. restart the node process)?

Answer

John David Anderson picture John David Anderson · Apr 6, 2012

Here's an adjusted version of Pendlepants solution. Foreman looks for an .env file to read environment variables. Rather than adding a wrapper, you can just have Foreman switch what command it uses to start things up:

In .env:

WEB=node app.js

In dev.env:

WEB=supervisor app.js

In your Procfile:

web: $WEB

By default, Foreman will read from .env (in Production), but in DEV just run this:

foreman start -e dev.env