AI Skill Report Card

Applying Alibaba Node.js Conventions

A-82·Sep 20, 2026·Source: Extension-page
13 / 15

Apply these conventions when writing or reviewing Node.js code:

JavaScript
// ✅ Good: destructure built-in globals, promises API, proper import order, native Error const fs = require('fs').promises; const http = require('http'); const moment = require('moment'); const Car = require('./models/car'); async function readConfig(path) { try { return await fs.readFile(path, 'utf8'); } catch (err) { throw err; // never throw a literal } }

Supported Node.js versions: Current, Active LTS, Maintenance LTS only. Never target Unstable/EOL versions, and avoid odd-numbered versions (19, 21, 23) in production — their support window is only 6 months.

Recommendation
Add a bad-example counterpart for the Quick Start snippet to reinforce good vs bad contrast (currently only shows good code with inline comments).
14 / 15

When reviewing/writing Node.js code, check in this order:

Progress:
- [ ] 1. Verify Node.js version target (LTS/Current only, avoid odd versions)
- [ ] 2. Check coding style (globals, promises, import order, error throwing, no sync I/O)
- [ ] 3. Check security rules (error leakage, headers, JSONP, auth, SQL injection, uploads, redirects, input validation)
- [ ] 4. Check best practices (statelessness, static files, CPU-bound tasks, async/await, monitoring)
- [ ] 5. Recommend eslint-config-ali/node (or /typescript/node) for automated enforcement

1. Coding Style

  • Prefer built-in globals over require-ing them explicitly where Node exposes globals (Buffer, URL, URLSearchParams, TextEncoder, TextDecoder, process, console). ESLint: node/prefer-global.
  • Prefer built-in promise APIs over callback style: require('dns').promises, require('fs').promises (Node ≥ v11.14.0). ESLint: node/prefer-promises.
  • Import order (ESLint: import/order), each group separated by a blank line, alphabetical within group (destructured imports sorted by first named import, and internally):
    1. Node built-in modules
    2. npm packages
    3. Local files (relative paths)
  • Throw only Error objects/instances, never literals, strings, or undefined. ESLint: no-throw-literal.
  • Never use sync methods (fs.readFileSync, child_process.execSync, etc.) in production code paths — they block the event loop. Use fs.promises or a library like mz.

2. Security Rules (mandatory unless noted "recommended")

RuleRequirement
Error exposureHide detailed error info/stack traces from clients
Framework fingerprintHide or fake X-Powered-By and other stack-identifying headers
JSONPStrictly validate request origin via a domain whitelist
Sensitive lookupsNever trust user identity from query params or plaintext cookies for sensitive queries (prevents unauthorized/privilege-escalation access)
SQL injectionUse prepared statements for any SQL containing user input; escape/whitelist input used for table/column names
Dependencies (recommended)Regularly audit for outdated/vulnerable deps and upgrade
File uploads (recommended)Never store user uploads on local disk — upload to OSS/object storage
Redirects (recommended)Whitelist target domains before redirecting based on user input
Input validation (recommended)Validate all request input using jsonschema or joi

3. Best Practices

  • Stateless services: use external stores; killing an instance must not lose data.
  • Don't serve static files from Node — offload to CDN to avoid blocking other request handling.
  • Delegate CPU-intensive work (gzip, TLS termination) to a reverse proxy (nginx) rather than doing it in Node.
  • Prefer async/await over raw callbacks/promise chains to avoid callback hell and simplify error handling.
  • Use util.promisify to convert callback-style APIs:
    JavaScript
    const util = require('util'); const fs = require('fs'); const stat = util.promisify(fs.stat);
  • Use native Promise, not third-party libraries like bluebird.
  • Return this from instance methods to enable method chaining:
    JavaScript
    class Jedi { jump() { this.jumping = true; return this; } setHeight(h) { this.height = h; return this; } }
  • Use a Node.js performance monitoring tool (e.g., Alibaba Cloud Node.js Performance Platform) for APM, heap snapshots, dependency/security alerts, and slow-HTTP/error logging.
Recommendation
Include an ESLint config snippet or link showing how to actually wire up eslint-config-ali/node, since it's recommended but not demonstrated.
15 / 20

Example 1 — Import order violation Input:

JavaScript
const Car = require('./models/car'); const moment = require('moment'); const fs = require('fs');

Output:

JavaScript
const fs = require('fs'); const moment = require('moment'); const Car = require('./models/car');

Example 2 — Sync I/O in a request handler Input:

JavaScript
app.get('/file', (req, res) => { const data = fs.readFileSync('./somefile', 'utf-8'); res.send(data); });

Output:

JavaScript
const fs = require('fs').promises; app.get('/file', async (req, res) => { const data = await fs.readFile('./somefile', 'utf-8'); res.send(data); });

Example 3 — Throwing a literal Input: throw 'Invalid input'; Output:

JavaScript
throw new Error('Invalid input');
Recommendation
Expand security examples with concrete before/after code (like the SQL injection or JSONP whitelist patterns) rather than only describing them in a table.
  • Don't leak stack traces or internal error messages to API clients.
  • Don't leave X-Powered-By or similar headers exposing the framework.
  • Don't build SQL by string concatenation with user input — always use prepared statements.
  • Don't accept identity from query params/plaintext cookies for authorization decisions.
  • Don't use fs.*Sync / child_process.*Sync in server request paths.
  • Don't target Node.js Unstable or EOL versions, or odd-numbered releases in production.
  • Don't mix import ordering arbitrarily — group and alphabetize consistently.
  • Don't reach for bluebird or similar when native Promise suffices.
0
Grade A-AI Skill Framework
Scorecard
Criteria Breakdown
Quick Start
13/15
Workflow
14/15
Examples
15/20
Completeness
17/20
Format
15/15
Conciseness
13/15