For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/predicate/isNode.md.

isNode es-toolkit

Checks if the current runtime environment is Node.js.

const result = isNode();

Usage

isNode()

Use isNode when you want to check if the current code is running in a Node.js environment. It's useful for verifying the environment before using Node.js-specific APIs.

import { isNode } from 'es-toolkit/predicate';

if (isNode()) {
  // Node.js-specific code
  console.log('This code is running in Node.js');
  const fs = await import('node:fs');
  const path = await import('node:path');
} else {
  // Browser-only code
  console.log('This code is running in a browser');
  const response = await fetch('/api/data');
}

It's also useful when conditionally using Node.js modules:

function getEnvironmentInfo() {
  if (isNode()) {
    return {
      platform: process.platform,
      nodeVersion: process.version,
      environment: 'Node.js',
    };
  } else {
    return {
      userAgent: navigator.userAgent,
      environment: 'Browser',
    };
  }
}

Returns

Returns true if the current environment is Node.js, false otherwise.

boolean
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.