profile image
Sean Walker
2020-08-06

Switching from fswatch to entr

Restarting development servers has a long, storied history. No I’m kidding I’m not going to get into that, but I will say there are three main ways to see changes in your server show up on your web app:

  1. Go to terminal then Ctrl+C then go to browser and Cmd+R
  2. Restart development server on file change, only have to Cmd+R
  3. Hot reload changes in browser on file change

Manual restart

This is not premature optimization, it’s necessary. You need to figure something out to avoid this, don’t do this.

Restart on file change

This is where I’m currently at with joy, and I think most server side development takes place like this, even with some of the bigger web frameworks like rails. It stinks to have to lose your state if you opened a modal or typed some text in an input, but it’s do-able.

Hot reload

This is the holy grail. I think it’s possible to do this without the overhead of things like react, you could cobble together a websocket server that takes whatever currently html is showing, diff it against the newly restarted server and then put it back in the same page with javascript, modals stay open, text stays in the inputs, no state loss.

fswatch -> entr

joy was using fswatch like this in the default template:

fswatch -o . --exclude='.git' --exclude='.sqlite3' | xargs -n1 -I{} ./watch

and this need a whole separate file with execution permission to restart the server:

#!/usr/bin/env sh

pkill -xf "janet main.janet"
sleep .5
janet main.janet &

Madness. I saw entr on HN and it was all over, I switched right away, same effect with less code:

find . -name '*.janet' | entr -r -d janet main.janet

If the whole directory changes, it fails, but I can just put it in a while and it’ll keep going. If you’re using fswatch, switch to entr.