CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-builtin-modules

A static list of the Node.js builtin modules from the latest Node.js version

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

index.mddocs/

Builtin Modules

Builtin Modules provides a static, curated list of Node.js built-in modules exported as a JSON array. It serves as a reliable reference for developers who need to programmatically identify or work with Node.js core modules across different Node.js versions, offering consistent behavior without runtime dependencies.

Package Information

  • Package Name: builtin-modules
  • Package Type: npm
  • Language: JavaScript (ES Module with TypeScript definitions)
  • Installation: npm install builtin-modules
  • Node.js Requirements: >=18.20

Core Imports

import builtinModules from "builtin-modules";

For CommonJS (via dynamic import):

const { default: builtinModules } = await import("builtin-modules");

Basic Usage

import builtinModules from "builtin-modules";

console.log(builtinModules);
//=> ['node:assert', 'assert', 'node:buffer', 'buffer', 'node:child_process', 'child_process', ...]

// Check if a module is built-in
const isBuiltIn = builtinModules.includes('fs');
console.log(isBuiltIn); //=> true

// Filter for prefixed modules only
const prefixedModules = builtinModules.filter(mod => mod.startsWith('node:'));
console.log(prefixedModules);
//=> ['node:assert', 'node:buffer', 'node:child_process', ...]

// Count total built-in modules
console.log(`Total built-in modules: ${builtinModules.length}`);

// Check for special cases and edge cases
console.log(builtinModules.includes('node:test')); //=> true
console.log(builtinModules.includes('test')); //=> false (special case)

// Verify deprecated modules are excluded
console.log(builtinModules.includes('sys')); //=> false (deprecated)
console.log(builtinModules.includes('punycode')); //=> false (deprecated)

Capabilities

Built-in Module List

Provides access to a comprehensive, static list of all Node.js built-in module names.

declare const builtinModules: readonly string[];
export default builtinModules;

The array contains strings representing Node.js built-in module names in both prefixed and non-prefixed formats:

  • Core modules: 'assert', 'buffer', 'crypto', 'fs', 'http', 'path', etc.
  • Prefixed variants: 'node:assert', 'node:buffer', 'node:crypto', 'node:fs', etc.
  • Submodules: 'assert/strict', 'node:assert/strict', 'fs/promises', 'node:fs/promises', etc.
  • Special modules: 'inspector/promises', 'node:inspector/promises', etc.

Key characteristics:

  • Static data: Pre-compiled list ensuring consistent results across environments
  • Read-only: Exported as readonly string[] preventing accidental modification
  • Zero dependencies: No external dependencies for maximum reliability
  • Version-specific: List corresponds to Node.js built-in modules as of the package version
  • Comprehensive: Includes both legacy and modern module naming conventions

Common use cases:

  • Bundlers: Distinguish between built-in modules and external packages during bundling
  • Linters: Validate import statements and identify core modules vs. user dependencies
  • Dependency analyzers: Categorize imports and analyze project dependency patterns
  • Build tools: Configure module resolution and bundling strategies
  • Testing utilities: Mock or stub built-in modules in test environments

Module Inclusion Rules:

The array follows specific inclusion patterns:

  • Most core modules: Both prefixed and non-prefixed variants (e.g., 'fs' and 'node:fs')
  • Submodules: Both prefixed and non-prefixed variants (e.g., 'fs/promises' and 'node:fs/promises')
  • Special cases: Some modules only have prefixed variants (e.g., 'node:test' included, but 'test' excluded)
  • Deprecated modules: Explicitly excluded (e.g., 'sys', 'punycode' not included in either form)

Data structure example:

The array includes entries such as:

[
  'node:assert',
  'assert', 
  'node:assert/strict',
  'assert/strict',
  'node:buffer',
  'buffer',
  'node:child_process',
  'child_process',
  'node:crypto',
  'crypto',
  'node:fs',
  'fs',
  'node:fs/promises',
  'fs/promises',
  'node:test',        // Note: 'test' (non-prefixed) is not included
  'node:test/reporters',
  // ... 109 total entries
]

Alternative Approaches

For runtime detection of built-in modules on the current Node.js version:

import { builtinModules } from 'node:module';
// Returns modules available in the current Node.js runtime

The builtin-modules package provides a static alternative that:

  • Works consistently across different Node.js versions
  • Avoids runtime dependencies on Node.js APIs
  • Provides predictable results for build tools and static analysis
  • Includes comprehensive module variants (prefixed, submodules, etc.)

Install with Tessl CLI

npx tessl i tessl/npm-builtin-modules

docs

index.md

tile.json