Make it work in node.js as well as browser

Also make sure tests get run in both environments.