Node.js globals for node-webkit's HTML5
These issues happen in node-webkit because, as the modules run in Node context, the constructors of their global objects (such as
ArrayBuffer or even
Array) differ from WebKit's.
(An example below demonstrates that you may pass an array from some
<script>…</script> to the async module that you have previously
required, but that module cannot recognize such an array.)
To prevent the trouble,
nwglobal exports Node's constructors. You may use them instead of the constructors available in WebKit's context, and then you may pass the resulting object instances to any Node code.
Latest packaged version:
npm install nwglobal
Latest githubbed version:
npm install https://github.com/Mithgol/nwglobal/tarball/master
You may visit https://github.com/Mithgol/nwglobal#readme occasionally to read the latest
README because the package's version is not planned to grow after changes when they happen in
README only. (And
npm publish --force is forbidden nowadays.)
Classic async waterfall example:
does not report
'done' in node-webkit (issue #832), but can be fixed with the following changes:
The following Node.js globals are available as the exported fields of
Standard object types:
Typed array types:
Special value types:
However, the latter four (
null) are actually superglobal (i.e. they are the same in Node's and WebKit's contexts). You may use
nwglobal to check it with the following four statements in node-webkit's “Developer Tools” console:
null === require('nwglobal').null
typeof require('nwglobal').undefined === 'undefined'
Infinity === require('nwglobal').Infinity
isNaN( require('nwglobal').NaN )
These statements are
true. (Meaning that you won't need these four exported values IRL.)
It is not possible to replace the default constructors of arrays and objects created by
Therefore you have to use
Object() constructors exported by
require('nwglobal') in order to create arrays and objects in Node's context.
NB: you can cast browser's
 array to node.js array with
NB2: With this you can transform jquery set.
MIT License, see the LICENSE file.