Debugging Node's spawn ENOENT

Just figured out a bug that was really annoying. I was running a shell command from Node, and it was working fine in some cases, but failed for my new test with the cryptic error:

spawn /bin/sh ENOENT

That was it. But of course /bin/sh exists, so what's going on?

Turns out, this error means something doesn't exist, not /bin/sh. It turns out that the cwd I was setting the command to was incorrect, and in fact, didn't exist.

So when this occurs, check to see what variables are undefined when you don't expect them to be.