Cursor's training data includes older Node.js code, causing it to generate deprecated APIs like url.parse(), fs.exists(), and the domain module. By adding Node.js version rules to .cursorrules and using @docs to index current Node.js documentation, you ensure Cursor generates modern, supported API calls that will not break in future Node.js versions.
Why Cursor uses deprecated APIs and how to fix it
Cursor's training data spans decades of Node.js code, including deprecated patterns from Node.js 8-16 era. Without version constraints, it generates url.parse() instead of new URL(), fs.existsSync() instead of fs.accessSync(), and callback-based fs methods instead of fs.promises. This tutorial pins Cursor to modern Node.js APIs.
Prerequisites
- Cursor installed with a Node.js project
- Node.js 18+ installed
- package.json with engine requirements
- Familiarity with Cursor Chat (Cmd+L) and Cmd+K
Step-by-step guide
Add Node.js version rules to .cursor/rules
Add Node.js version rules to .cursor/rules
Create rules that specify your Node.js version and list deprecated APIs with their modern replacements. This prevents Cursor from generating outdated code.
1---2description: Node.js API version rules3globs: "src/**/*.ts,src/**/*.js"4alwaysApply: true5---67## Node.js Version: 22 (LTS)89## Deprecated → Modern Replacements10| Deprecated | Use Instead |11|-----------|------------|12| url.parse() | new URL() |13| querystring.parse() | URLSearchParams |14| fs.exists() | fs.access() or fs.stat() |15| fs.readFile(cb) | fs.promises.readFile() |16| Buffer(string) | Buffer.from(string) |17| util.puts() | console.log() |18| domain module | AsyncLocalStorage |19| util.isArray() | Array.isArray() |20| require() in ESM | import |21| crypto.createCipher() | crypto.createCipheriv() |2223## Rules24- ALWAYS use fs.promises (import fs from 'node:fs/promises')25- ALWAYS use node: protocol prefix (node:fs, node:path, node:crypto)26- NEVER use callback-based fs methods27- Use native fetch() instead of http.request() for HTTP calls28- Use structuredClone() instead of JSON.parse(JSON.stringify())29- Use AbortController instead of manual timeout handlingExpected result: Cursor generates modern Node.js APIs matching your target version.
Index current Node.js docs with @docs
Index current Node.js docs with @docs
Use Cursor's @docs feature to index the latest Node.js documentation. This gives the AI current API information to reference.
1// In Cursor Settings → Features → Docs:2// 1. Click 'Add new doc'3// 2. Enter URL: https://nodejs.org/api/4// 3. Name it: 'Node.js 22 API'5// 4. Wait for indexing to complete6//7// Now use in prompts:8// @docs:Node.js 22 API Generate a file reader using the9// current recommended fs API.Pro tip: Index specific Node.js documentation pages for the APIs you use most: fs, path, crypto, http, stream. This gives Cursor precise, current reference material.
Expected result: Current Node.js documentation indexed and available via @docs in prompts.
Audit existing code for deprecated APIs
Audit existing code for deprecated APIs
Use Cursor to scan your codebase for deprecated Node.js API usage that may have been generated in earlier sessions.
1// Cursor Chat prompt (Cmd+L, Ask mode):2// @codebase Find all uses of deprecated Node.js APIs in src/:3// 1. url.parse() → should be new URL()4// 2. querystring.parse() → should be URLSearchParams5// 3. Callback-based fs (fs.readFile with callback)6// → should be fs.promises.readFile()7// 4. Buffer() constructor → should be Buffer.from()8// 5. require() in .ts files → should be import9// 6. fs without node: prefix → should be node:fs10// List each finding with file, line, and the modern replacement.Expected result: A complete list of deprecated API usage across your codebase.
Replace deprecated APIs with Cmd+K
Replace deprecated APIs with Cmd+K
For each deprecated API found, select the code and use Cmd+K to modernize it. Cursor generates the correct modern equivalent.
1// DEPRECATED:2const parsed = url.parse(req.url, true);3const name = parsed.query.name;45// Select and press Cmd+K:6// 'Replace url.parse with new URL(). Use Node.js 22 API.'78// MODERN:9const parsed = new URL(req.url, `http://${req.headers.host}`);10const name = parsed.searchParams.get('name');Expected result: Deprecated API replaced with the modern equivalent.
Verify with Node.js deprecation warnings
Verify with Node.js deprecation warnings
Run your code with deprecation warnings enabled to catch any remaining deprecated API usage.
1// Terminal: Run with deprecation warnings2NODE_OPTIONS='--throw-deprecation' npm test34// This makes Node.js throw an error (not just warn) when5// deprecated APIs are called, ensuring all are caught.6//7// Common deprecation warnings:8// DEP0005: Buffer() constructor9// DEP0025: require('sys')10// DEP0079: url.resolve()11// DEP0106: crypto.createDecipher()Expected result: No deprecation warnings or errors, confirming all APIs are current.
Complete working example
1---2description: Modern Node.js API rules (Node 22 LTS)3globs: "src/**/*.{ts,js}"4alwaysApply: true5---67## Runtime: Node.js 22 LTS89## Module System10- Use ESM imports (import/export), not require()11- Use node: protocol prefix for built-ins:12 import fs from 'node:fs/promises';13 import path from 'node:path';14 import { createHash } from 'node:crypto';1516## File System17- ALWAYS use fs/promises: import fs from 'node:fs/promises'18- NEVER use callback-based fs methods19- Use fs.access() to check existence, not fs.exists()20- Use fs.readFile(path, 'utf-8') for text files2122## URLs and Query Strings23- Use new URL() instead of url.parse()24- Use URLSearchParams instead of querystring module25- Use URL.canParse() for validation2627## HTTP28- Use native fetch() for HTTP requests (Node 21+)29- Use AbortController for timeouts30- Use node:http2 for HTTP/2 support3132## Buffers33- Use Buffer.from() and Buffer.alloc()34- NEVER use new Buffer() (deprecated)3536## Crypto37- Use crypto.createCipheriv(), not createCipher()38- Use crypto.randomUUID() for UUID generation39- Use crypto.subtle for WebCrypto API4041## Utilities42- Use structuredClone() for deep cloning43- Use AsyncLocalStorage for request context44- Use AbortController for cancellation45- Use Array.isArray(), not util.isArray()Common mistakes
Why it's a problem: Cursor using require() in TypeScript files
How to avoid: Add 'Use ESM imports (import/export), not require()' to .cursorrules. Specify 'type: module' in package.json.
Why it's a problem: Cursor using callback-based fs methods
How to avoid: Add 'ALWAYS use fs/promises' to your rules. Import as: import fs from 'node:fs/promises'
Why it's a problem: Missing node: protocol prefix on built-in imports
How to avoid: Add 'Use node: protocol prefix for built-ins' to .cursorrules.
Best practices
- Specify your Node.js version in .cursorrules to constrain API suggestions
- Use the node: protocol prefix for all built-in module imports
- Index current Node.js documentation with @docs for up-to-date API references
- Use fs/promises instead of callback-based fs methods
- Use new URL() and URLSearchParams instead of url.parse() and querystring
- Run with --throw-deprecation in tests to catch deprecated API usage
- Audit your codebase periodically with @codebase for deprecated patterns
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
I have a Node.js 22 project. Create a comprehensive list of deprecated Node.js APIs and their modern replacements. Group by module (fs, url, crypto, buffer, util). For each deprecated API, show the old usage and the modern equivalent with a code example. Include the DEP number where applicable.
In Cursor Chat (Cmd+L): @.cursor/rules/nodejs.mdc @codebase Find all deprecated Node.js API usage in src/. Replace each with the modern equivalent from our Node.js 22 rules. Show the before/after for each change.
Frequently asked questions
Why does Cursor suggest deprecated APIs?
Cursor's training data includes Node.js code from all eras. Deprecated APIs like url.parse() appear millions of times in existing code, making them the most common pattern the model has seen.
Will deprecated APIs stop working immediately?
No. Node.js deprecates APIs gradually. Most deprecated APIs still work but emit warnings. However, they may be removed in future major versions, so migrating early is wise.
How do I check which Node.js version I am running?
Run 'node --version' in your terminal. Update your .cursorrules to match. If your deployment targets a different version, use the deployment version in your rules.
Can I use @docs for framework documentation too?
Yes. Index Express, Fastify, or NestJS docs alongside Node.js docs. Cursor can reference multiple doc sources in a single prompt using @docs:name syntax.
Should I use the node: prefix for third-party packages?
No. The node: prefix is only for Node.js built-in modules. Third-party packages are imported normally: import express from 'express'.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation