Refactor Node.js detection.

Node.js detection fails if any node modules set global.window.