Skip to main content
RapidDev - Software Development Agency
cursor-tutorial

Why Cursor uses deprecated APIs

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.

What you'll learn

  • Why Cursor suggests deprecated Node.js APIs
  • How to add Node.js version rules to .cursorrules
  • How to use @docs to index current Node.js documentation
  • How to audit and replace deprecated APIs in your codebase
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Beginner6 min read10-15 minCursor Free+, Node.js 18+ projectsMarch 2026RapidDev Engineering Team
TL;DR

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

1

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.

.cursor/rules/nodejs.mdc
1---
2description: Node.js API version rules
3globs: "src/**/*.ts,src/**/*.js"
4alwaysApply: true
5---
6
7## Node.js Version: 22 (LTS)
8
9## Deprecated Modern Replacements
10| 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() |
22
23## Rules
24- 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 methods
27- Use native fetch() instead of http.request() for HTTP calls
28- Use structuredClone() instead of JSON.parse(JSON.stringify())
29- Use AbortController instead of manual timeout handling

Expected result: Cursor generates modern Node.js APIs matching your target version.

2

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.

Cursor Settings
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 complete
6//
7// Now use in prompts:
8// @docs:Node.js 22 API Generate a file reader using the
9// 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.

3

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.

Cursor Chat prompt
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 URLSearchParams
5// 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 import
9// 6. fs without node: prefix → should be node:fs
10// List each finding with file, line, and the modern replacement.

Expected result: A complete list of deprecated API usage across your codebase.

4

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.

Cursor Cmd+K
1// DEPRECATED:
2const parsed = url.parse(req.url, true);
3const name = parsed.query.name;
4
5// Select and press Cmd+K:
6// 'Replace url.parse with new URL(). Use Node.js 22 API.'
7
8// 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.

5

Verify with Node.js deprecation warnings

Run your code with deprecation warnings enabled to catch any remaining deprecated API usage.

Terminal
1// Terminal: Run with deprecation warnings
2NODE_OPTIONS='--throw-deprecation' npm test
3
4// This makes Node.js throw an error (not just warn) when
5// deprecated APIs are called, ensuring all are caught.
6//
7// Common deprecation warnings:
8// DEP0005: Buffer() constructor
9// 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

.cursor/rules/nodejs.mdc
1---
2description: Modern Node.js API rules (Node 22 LTS)
3globs: "src/**/*.{ts,js}"
4alwaysApply: true
5---
6
7## Runtime: Node.js 22 LTS
8
9## Module System
10- 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';
15
16## File System
17- ALWAYS use fs/promises: import fs from 'node:fs/promises'
18- NEVER use callback-based fs methods
19- Use fs.access() to check existence, not fs.exists()
20- Use fs.readFile(path, 'utf-8') for text files
21
22## URLs and Query Strings
23- Use new URL() instead of url.parse()
24- Use URLSearchParams instead of querystring module
25- Use URL.canParse() for validation
26
27## HTTP
28- Use native fetch() for HTTP requests (Node 21+)
29- Use AbortController for timeouts
30- Use node:http2 for HTTP/2 support
31
32## Buffers
33- Use Buffer.from() and Buffer.alloc()
34- NEVER use new Buffer() (deprecated)
35
36## Crypto
37- Use crypto.createCipheriv(), not createCipher()
38- Use crypto.randomUUID() for UUID generation
39- Use crypto.subtle for WebCrypto API
40
41## Utilities
42- Use structuredClone() for deep cloning
43- Use AsyncLocalStorage for request context
44- Use AbortController for cancellation
45- 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.

ChatGPT Prompt

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.

Cursor Prompt

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'.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.