Skip to content
Learn Netverks

Lesson

Step 28/36 78% through track

security-basics

Security basics for Node APIs

Last reviewed May 28, 2026 Content v20260528
Track mode
nodejs_server
Means
Node sandbox
Reading
~1 min
Level
advanced

This lesson

This lesson teaches Security basics for Node APIs: the syntax, APIs, and habits you need before advancing in Node.js.

Teams ship Security basics for Node APIs on every Node.js codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Security basics for Node APIs in contexts like: REST/GraphQL APIs, BFF layers, CLIs, webhooks, and real-time services (with WebSockets).

Run JavaScript on the Node runner when configured—never mix arbitrary shell commands in lessons.

When functions, arrays, and basic OOP from intermediate lessons are familiar.

Node servers face the same threats as PHP or Java backends—injection, broken auth, sensitive data exposure, and misconfiguration. Security is layered defaults plus disciplined code.

Core defenses

  • Validate input — schemas at boundaries; parameterized queries for SQL
  • Authn/Authz — verify identity, then check permissions per resource
  • Helmet — security headers (CSP, X-Frame-Options) in Express
  • Rate limiting — slow brute-force on login routes
  • Dependenciesnpm audit, lockfiles, minimal packages

Common mistakes

  • Logging passwords or tokens
  • Detailed stack traces in JSON error responses
  • CORS set to * with credentials
  • Path traversal in file download routes

Important interview questions and answers

  1. Q: SQL injection in Node?
    A: Still possible with string concatenation—use parameterized queries (pg, mysql2, Prisma).
  2. Q: CSRF for cookie auth?
    A: SameSite cookies, CSRF tokens on state-changing forms, or use token auth without cookies.

Self-check

  1. Name two headers Helmet helps set.
  2. Why avoid * CORS with credentials?

Pitfall: Never commit .env files—use environment variables in production and rotate leaked keys immediately.

Interview prep

Helmet and rate limiting?

Helmet sets security HTTP headers; rate limiting caps requests per IP/key to reduce brute-force and abuse—both are common Express middleware.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Helmet-style headers?
  • Rate limit where?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump