nodeProtocols
Prefer the
node:protocol prefix for Node.js built-in modules for clarity and consistency.
✅ This rule is included in the node logical preset.
The node: protocol makes it explicit that the module is a Node.js built-in, preventing confusion with npm packages that might have the same name.
The protocol is supported in Node.js 16+ and is the recommended way to import built-ins.
Examples
Section titled “Examples”import fs from "fs";
import path from "path";
import { readFile } from "fs";
import fsPromises from "fs/promises";
const crypto = require("crypto");import fs from "node:fs";
import path from "node:path";
import { readFile } from "node:fs";
import fsPromises from "node:fs/promises";
const crypto = require("node:crypto");Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you need to support Node.js versions older than 16, you should not use this rule, as the node: protocol was introduced in Node.js 16.0.0.
If you strongly prefer more succinct imports and aren’t worried about confusing userland modules with built-in Node.js modules, this rule might not be for you.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.