_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN
Let's talk

Node.js Best Practices

07. 07. 2023 1 min read intermediate

Node.js v produkci vyžaduje jiný přístup než localhost. Error handling, graceful shutdown, clustering.

Error handling

// Global uncaught handler process.on(‘uncaughtException’, (err) => { logger.fatal(‘Uncaught exception’, err); process.exit(1); }); // Async error handling app.use(async (err, req, res, next) => { logger.error(‘Request error’, { err, path: req.path }); res.status(err.status || 500).json({ error: ‘Internal error’ }); });

Graceful shutdown

const server = app.listen(3000); process.on(‘SIGTERM’, async () => { logger.info(‘SIGTERM received, shutting down…’); server.close(() => { db.close(); process.exit(0); }); setTimeout(() => process.exit(1), 10000); });

Security

const helmet = require(‘helmet’); app.use(helmet()); // Security headers // Rate limiting, input validation (zod), prepared statements // Viz security články v Know-How sekci

Key Takeaway

Graceful shutdown, global error handling, helmet, structured logging. Node.js v produkci ≠ node app.js.

node.jsjavascriptbest practices
Share:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.