What are built-in modules in Node.js

· Category: Node.js

Short answer

Built-in modules are core libraries included with Node.js that provide essential functionality like file system access, networking, path utilities, and cryptography.

How it works

You import them with require() or import without specifying a file path. For example, const fs = require('fs'); loads the file system module. These modules are written in C++ and JavaScript for high performance.

Example

const os = require('os');
console.log(os.platform());
console.log(os.cpus().length);

Popular built-in modules include: - fs: file system operations - http / https: web servers - path: cross-platform path handling - os: operating system information - crypto: hashing and encryption - events: event emitter pattern - stream: data streaming - util: utility functions

Why it matters

Using built-in modules reduces your dependency footprint, improves security by avoiding third-party code, and ensures compatibility with your Node.js version.