Controlling nodeIntegration in NW.js window configuration
Enabling Node.js APIs in NW.js requires pairing nodeIntegration: true with contextIsolation: false; without it the flag is silently ignored. Here’s how to configure, verify, and avoid the common pitfall.
22 Jul 2025, 20:01 UTC

When an NW.js window loads HTML Node.js APIs are not available by default. The nodeIntegration flag in the window configuration toggles whether require() and other Node globals become accessible in the renderer. Getting this right matters for both functionality and security.
The useful answer
If you need Node.js APIs available in your NW.js renderer add nodeIntegration: true and contextIsolation: false to the window section of your package.json. Without contextIsolation: false the nodeIntegration flag is silently ignored. Verify the setting is active by opening Chromium developer tools and running typeof process; the result should be the string "object".
How the flag works
The nodeIntegration option lives inside the window object of your package.json. It is a boolean that when true exposes Node.js module loading and system globals to the HTML content rendered in the NW.js window. In recent maintained builds the default is false a deliberate security change from earlier NW.js releases that defaulted to true.
{{ "name": "my-nw-app", "window": { "nodeIntegration": true, "contextIsolation": false }} }This configuration enables require() from loaded pages. It is particularly useful when migrating legacy desktop tools that depend on Node modules being directly available in the UI layer.
The contextIsolation trap
A common mistake is setting nodeIntegration: true without also setting contextIsolation: false. In NW.js the two flags are bridged: when contextIsolation is left at its default true the nodeIntegration setting is effectively ignored. The renderer creates an isolated context and Node APIs are not injected even though the flag appears set. This leads to silent failures where require is undefined and no error is thrown during setup.
If you need require() in the renderer and want to keep context isolation for security you must use contextBridge to selectively expose specific modules rather than enabling nodeIntegration globally.
Version defaults and migration
The nodeIntegration default has shifted over time. Early NW.js versions assumed true by default which made Node APIs available without explicit configuration. Maintained forks and the actively maintained nw.js lineage now default to false. If you are upgrading an older project check your package.json explicitly do not rely on implicit behavior. The flag is also version-sensitive in forked builds so pin your NW.js version in package-lock.json or yarn.lock if stability of this behavior is critical.
Verification in practice
To confirm that Node integration is active for a given window open the Chromium developer tools (F12 or Ctrl+Shift+I) and evaluate:
typeof processIf the console returns the string "object" Node integration is active for that window. You can also launch the application from a terminal and check that process.version reports the bundled NW.js runtime version confirming the integration is functional across the full launch path. Finally inspect the effective configuration by loading any HTML file served by your NW.js app and checking that the window object in package.json matches the observed behavior. If the values differ from what you see in the console the renderer may be loading a different configuration or a remote source that overrides the setting.Limits and common mistakes
- Untrusted content risk. Enabling
nodeIntegration: trueon windows that load remote or untrusted HTML grants full system-level Node.js execution. Treat this as a privilege not a default. - Omitting
contextIsolation: false. Without it the flag is ignored. Always set both together when you needrequire()in the renderer. - Assuming the flag persists across reloads. If your NW.js app loads content from a network source the setting may be overridden by the remote URL’s security policy.
Practical check: after configuring package.json restart the NW.js instance and re-run typeof process in the developer tools. If the result changes unexpectedly verify that no external script is overwriting the renderer context.
Conclusion
Node.js integration in NW.js is a deliberate configuration choice not an implicit behavior. Set nodeIntegration: true and contextIsolation: false together in package.json verify with typeof process and always weigh the security implications for the content your window loads.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.