Skip to content
Tutorials Center
My learning

Topics

Node.js Reference ยท Module Systems

Node.js module.builtinModules property

Reference for module.builtinModules and module.isBuiltin() in Node.js: list core modules, test whether a specifier is built in, node: prefix rules and caveats.

module.builtinModules is an array of the names of the modules that ship inside Node.js: fs, path, http, fs/promises and so on. Tools use it to decide whether an import should be left alone or looked up in node_modules, and to warn about packages that shadow a core module.

Its companion module.isBuiltin(name) answers the same question for a single specifier and understands the node: prefix, which the plain array does not always show.

NODE
import { builtinModules, isBuiltin } from 'node:module';

console.log(builtinModules.includes('fs'));  // true
console.log(isBuiltin('node:fs'));           // true

Try it

Node.js Listing and testing built-in modules

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Node.js Finding names that need the node: prefix

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Syntax

NODE
import { builtinModules, isBuiltin } from 'node:module';

builtinModules: string[]
isBuiltin(moduleName: string): boolean
Name Description
builtinModules Array of core module names. Includes subpaths such as fs/promises and internal-looking _http_agent style names. Modules that exist only behind the node: scheme appear with the prefix.
moduleName The specifier to test. Both 'fs' and 'node:fs' count.

Returns: builtinModules is an array of strings. isBuiltin() returns true or false and never throws for a string.

Usage notes

  • Treat it as read-only. It describes what Node was built with; changing the array does not add or remove modules.
  • Do not assume every name is public. The array also contains legacy underscore names (_stream_readable) that exist for compatibility; filter them out when you show a list to users.
  • Prefix-only modules. Some modules (the second example prints which ones in your Node version) can only be imported as node:name. A bare import 'test' would look for a package called test, which is why isBuiltin('test') is false while isBuiltin('node:test') is true.
  • The set depends on the version and build. Experimental modules and those compiled out of a custom build may be missing, so never hard-code the list. Ask at run time.
  • Use isBuiltin() for validation. It is clearer than checking builtinModules.includes(name) and handles the prefix rules for you.
  • Not the same as "already loaded". The list says what could be imported, not what has been.
  • Alternative lookup: process.getBuiltinModule(name) returns the module object itself, or undefined, without any import statement.