Skip to content

Latest commit

 

History

History
52 lines (37 loc) · 1.18 KB

prefer-node-protocol.md

File metadata and controls

52 lines (37 loc) · 1.18 KB

Prefer using the node: protocol when importing Node.js builtin modules

💼 This rule is enabled in the ✅ recommended config.

🔧 This rule is automatically fixable by the --fix CLI option.

When getting builtin modules, it's better to use the node: protocol as it makes it perfectly clear that the package is a Node.js builtin module.

Examples

// ❌
import dgram from 'dgram';

// ✅
import dgram from 'node:dgram';
// ❌
export {strict as default} from 'assert';

// ✅
export {strict as default} from 'node:assert';
// ❌
import fs from 'fs/promises';

// ✅
import fs from 'node:fs/promises';
// ❌
const fs = require('fs/promises');

// ✅
const fs = require('node:fs/promises');
// ❌
const fs = process.getBuiltinModule('fs/promises');

// ✅
const fs = process.getBuiltinModule('node:fs/promises');