Enable Node.js in NW.js renderer windows
Configure window.node in package.json so renderer code can use require() for Node built-ins, with security limits and version checks.
16 Jan 2026, 10:24 UTC

Useful answer
If your NW.js desktop app needs to read files, spawn processes, or use npm modules from a renderer window, enable Node integration in that window. Set window.node to true in package.json, then call require() directly in renderer JavaScript. Browsers block this by default; NW.js exposes Node because the renderer runs inside the NW.js runtime, not an ordinary website.
Takeaway: enable node: true only for windows that load local, trusted HTML. Loading remote or untrusted URLs with Node integration exposed is equivalent to giving that page local code execution.
Mechanism: package.json and renderer code
NW.js distinguishes two entry points. main starts a Node.js background process, often with no window. window describes the browser window that loads your HTML UI. The window.node flag decides whether that renderer window (the Chromium-based window that displays your HTML) receives Node.js built-ins and modules.
Configuration
{
"name": "local-file-reader",
"main": "background.js",
"window": {
"title": "Local file reader",
"page": "index.html",
"node": true
}
}
Run the app from a terminal in the project directory:
$ /path/to/nw .
/path/to/nw is the NW.js binary for your target version. The dot tells NW.js to load the package.json in the current directory. No special permissions are required beyond executing the binary and reading the project files.
Renderer example
<script>
const fs = require('fs');
fs.readFile('/tmp/example.txt', 'utf8', (err, data) => {
if (err) {
console.error(err);
return;
}
console.log(data);
});
</script>
When window.node is enabled, require('fs') resolves to the Node.js built-in bundled with NW.js. The same pattern applies to npm modules installed into the project, provided any native addons are rebuilt for the NW.js ABI (application binary interface).
Version assumptions and verification
Behavior differs between NW.js major versions. Code written for the 0.x line often relies on require('nw.gui') or the nw global for window management. Modern releases expose different globals and APIs. Do not copy 0.x window-management snippets into a current project without checking the release notes for your installed version.
Practical check: launch the app and open the renderer DevTools console. Confirm that process.versions.nw exists and that require('fs') returns a module object. If either reference is undefined, Node integration is not active for that window.
Limits and common mistakes
- Remote content risk. Do not set
node: trueon a window that loads an untrusted remote URL. A cross-site scripting flaw in that page could callrequire('child_process')and execute commands on the host. - Confusing entry points.
mainandwindoware not interchangeable. Omittingwindow.pagecan launch the app headless, while pointingmainat HTML will fail becausemainexpects a Node script. - Native modules. A native Node module compiled for your system Node runtime usually fails to load in NW.js. Rebuild it against the NW.js headers matching the exact Chromium and Node versions in your release, then test
require()again. - Window globals. Do not assume
window.nworrequire('nw.gui')exists. Verify the exposed global for your NW.js version before using window open, close, or devtools APIs.
Rollback
Changing window.node from true to false removes Node access from the renderer. To revert, edit package.json, set node to false, and restart the app. No build artifacts are changed by this configuration edit alone.
Verification checklist
- Set
window.nodetotrueinpackage.jsonfor a window loading local HTML. - Launch with the NW.js binary matching your target version.
- Open DevTools in that renderer window.
- Run
console.log(process.versions.nw)andconsole.log(typeof require('fs')). - Expect a version string and
functionorobject, notundefined.
If the check fails, confirm the window is loading index.html through the window.page field and that the NW.js build was not launched with Node integration disabled by a command-line flag. Treat version-specific globals as unverified until compared against the release notes for your NW.js release.