Blog / Node Foreeever

Once you start poking around with Node.js, you want to run it all the time like an Apache site. Sitting at localhost:3000 feels so artificial. But the journey to a seamless Node site on Mac OS is as arduous as the quest to return the One Ring.

Spoiler: you’re Boromir.

Step one was getting the Node site running on port 80 without bothering Apache. Turns out this is impossible, at least if you want to keep the threading benefits that Node provides. I’m on a dev machine, so I don’t care. After trying five different incantations I found one that seems to work. I added this to the bottom of my virtual host definition for the Node site:

ProxyRequests off

<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>

<Location />
    ProxyPass http://localhost:3000/
    ProxyPassReverse http://localhost:3000/
</Location>

Easy. I think. There’s a possibility this messes up POST commands. Haven’t got there yet with my app. With the Node app running I get great performance through Apache.

Oh Jordan, you were doing so well with the TypeScript compiler.

But keeping that Node app running is annoying. Is there a way to have it run continuously, on startup, and reload itself whenever the JavaScript changes? Well yes, but not all of them. Supposedly some combination of Forever, NodeMon, Apple’s launchd, and a plist file will enable that behavior. But damned if I could get it to work. Forever wouldn’t run when called from the shell script I was invoking via the plist. I know it was working because the shell script touched files on my desktop.

So screw it, I thought, I’ll start the Node server manually and let it run all day…

… and eat my battery like a juicy apple. After 30 minutes of sitting idle my laptop started to get warm. Oh, so Node (or nodemon?) isn’t quite the low resource supercar I was led to believe. Guess I’ll go back to running Node manually.

Frustrating.