Hardening for Node.jss
Hardening is the practice of making a Node.js service resistant to attack. It covers common web attacks such as injection, cross-site scripting, CSRF and brute force, plus safe handling of configuration. Helmet sets security headers, rate limiting slows abuse, and secrets belong in environment variables or a vault.
Stage: Security and Auth · Part of the Node.js roadmap · Last reviewed 19 November 2026
What to learn in Hardening
- Prevent SQL and NoSQL injection by using parameters and validated input
- Add Helmet and CORS rules with sensible allowed origins
- Apply rate limiting to login and public endpoints
- Keep secrets in environment variables and out of Git history
- Run npm audit and update vulnerable dependencies regularly
Hardening interview questions
How do you protect an Express app from cross-site scripting?
Escape or encode user content on output, set a Content-Security-Policy header, and avoid inserting raw input into HTML. Cookies marked httpOnly keep scripts from reading session tokens. Helmet helps with several of these headers.
Why should secrets not be committed in a .env file?
Anything pushed to Git stays in history and can be copied from public or shared repositories. Keep .env out of version control with .gitignore, commit a sample file with placeholder values, and rotate any secret that has leaked.
Where Hardening fits in the Node.js roadmap
Hardening belongs to the Security and Auth stage (intermediate level), which takes about 22 hours. Protect the API.
Other units in this stage
Back to the full Node.js roadmap