Apparently people have had the idea before:http://en.wikipedia.org/wiki/Server-side_JavaScript
Most of these examples seem yucky for some reason (written in Java / closed-source / specific to Apache / etc.) to me, but they exist, FWIW.