{"id":11103,"library":"is-node","title":"is-node","description":"This package provides a minimal utility to programmatically determine if the current JavaScript execution environment is Node.js. It achieves this by checking for the presence of the global `process` object and specific properties like `process.versions.node`. The current stable version is 1.1.1. The package maintains a relatively active release cadence, primarily for patch updates related to build processes (e.g., `npm ignore`). Its key differentiator is its singular focus and small footprint, offering a straightforward boolean value rather than a complex function or object. It's commonly employed in isomorphic libraries or application code that needs to adapt behavior between server-side Node.js and client-side browser environments.","status":"active","version":"1.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/MatthewSH/npm-packages","tags":["javascript","is","node","detect","process","typescript"],"install":[{"cmd":"npm install is-node","lang":"bash","label":"npm"},{"cmd":"yarn add is-node","lang":"bash","label":"yarn"},{"cmd":"pnpm add is-node","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports a default boolean value (true if in Node.js, false otherwise), not a function or object. Use a default import for ESM.","wrong":"import { isNode } from 'is-node';","symbol":"isNode","correct":"import isNode from 'is-node';"},{"note":"For CommonJS, `require('is-node')` directly resolves to the exported boolean value.","wrong":"const { isNode } = require('is-node');","symbol":"isNode","correct":"const isNode = require('is-node');"},{"note":"The package ships with TypeScript types. The default export `isNode` is directly typed as a boolean, providing strong type inference.","symbol":"isNode","correct":"import isNode from 'is-node';\n// In TypeScript, 'isNode' is directly typed as a boolean"}],"quickstart":{"code":"import isNode from 'is-node';\n\nfunction logEnvironmentDetails() {\n  if (isNode) {\n    console.log(\"Detected: Running in a Node.js environment.\");\n    // Node.js-specific global objects and APIs are available here\n    console.log(`Node.js Version: ${process.version}`);\n    console.log(`Current Working Directory: ${process.cwd()}`);\n    // Example: process.stdout.write('Writing to stdout directly\\n');\n  } else {\n    console.log(\"Detected: Running in a non-Node.js environment (e.g., browser, Deno, Bun).\");\n    // Browser-specific APIs would be available here (e.g., document, window)\n    // console.log(`User Agent: ${navigator.userAgent}`);\n    // document.getElementById('app').innerHTML = 'Hello from the browser!';\n  }\n}\n\nlogEnvironmentDetails();","lang":"typescript","description":"Demonstrates how to import and use the `is-node` boolean to conditionally execute code, logging environment-specific details depending on whether the current runtime is Node.js."},"warnings":[{"fix":"For highly critical environment checks, consider more comprehensive or multi-factor detection strategies beyond `is-node` alone, or explicitly check for `process.versions.node` directly if that is the specific property your logic relies on.","message":"The `is-node` check relies on the global `process` object and specifically `process.versions.node`. While robust for typical Node.js environments, highly specialized or spoofed environments (e.g., some edge runtimes, custom JSDOM setups, or other JavaScript runtimes that partially emulate Node.js) might incorrectly report or fail to report as Node.js.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to `is-node@1.1.0` or later to leverage built-in TypeScript definitions and ensure proper type inference for the `isNode` boolean.","message":"Prior to version 1.1.0 (approximately, based on related package updates in the monorepo), the package might not have shipped TypeScript types directly. While not strictly a runtime breaking change, integrating older versions into TypeScript projects would require manual type declarations (`@types/is-node` or custom `d.ts`).","severity":"breaking","affected_versions":"<1.1.0"},{"fix":"If your application requires more granular environment detection (e.g., 'is in browser', 'is in Deno', 'is in Electron main/renderer'), use dedicated libraries or custom checks for those specific environments instead of relying solely on `is-node`.","message":"This package is designed for a single purpose: detecting the Node.js runtime. It does not provide browser-specific feature detection or differentiate between various non-Node.js runtimes (e.g., Deno, Bun, Web Workers, Electron render process).","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Do not attempt to call `isNode`. Use it directly as a boolean condition, e.g., `if (isNode) { /* ... */ }`.","cause":"`is-node` exports a boolean value directly, not a callable function.","error":"TypeError: isNode is not a function"},{"fix":"Change the import statement to a default import: `import isNode from 'is-node';`.","cause":"Attempting to use a named import for `is-node`, which is a default export.","error":"SyntaxError: Named export 'isNode' not found. The requested module 'is-node' does not provide an export named 'isNode'"},{"fix":"Ensure your build process correctly handles Node.js-specific code for different targets. If this error occurs in a browser environment, verify `is-node` itself is evaluating to `false` and that other Node.js assumptions are not present.","cause":"This error occurs if `is-node` is used in a non-Node.js environment where the global `process` object is entirely absent, and an upstream bundler or environment might not have correctly handled its Node.js-specific checks, or if other Node.js-specific code is executed assuming `process` is available.","error":"ReferenceError: process is not defined"}],"ecosystem":"npm"}