Create a GitHub Actions CI/CD pipeline for a Node.js web application. The pipeline should: run on push to main and on pull requests, install dependencies with caching, run linting (ESLint) and type checking (TypeScript), run unit tests with coverage reporting (fail if coverage drops below 80%), run integration tests against a PostgreSQL service container, build the production bundle, deploy to staging on PR merge and production on release tag. Include environment secrets management, Slack notification on failure, and a manual approval step before production deployment.
#34DevOps
Docker Multi-Stage Build
Write a production-optimized Dockerfile for a Node.js application using multi-stage builds. Stage 1 (builder): install all dependencies including devDependencies, run build/compile step. Stage 2 (production): use a minimal base image (alpine), copy only production dependencies and built output, set proper user permissions (non-root user), configure health check, expose the correct port, and use proper signal handling for graceful shutdown. Include a docker-compose.yml that runs the app with a PostgreSQL database and Redis cache, including volume mounts, networking, and environment variables.
#35DevOps
Deployment Script with Rollback
Write a deployment script (bash or Node.js) that automates deploying a web application to a Linux server via SSH. The script should: pull the latest code from git, install dependencies, run database migrations, build the application, gracefully restart the application server (zero-downtime using PM2 or similar), verify the deployment by hitting a health check endpoint, and automatically roll back to the previous version if the health check fails within 60 seconds. Include logging of each step with timestamps and a deployment history log file.
#36DevOps
Monitoring and Alerting Dashboard
Set up application monitoring using a structured logging approach. Create a logging middleware for Express.js that captures: request method, URL, status code, response time, request ID (UUID), user ID if authenticated, and error details for 4xx/5xx responses. Output logs in structured JSON format. Create a simple dashboard page that reads the last 24 hours of logs and displays: request volume over time (line chart), error rate percentage, slowest endpoints (table), most common error codes, and P50/P95/P99 response time percentiles. Include alert thresholds: error rate above 5%, P95 response time above 2 seconds.
#37DevOps
Environment Configuration Manager
Build an environment configuration system for a Node.js application that supports multiple environments (development, staging, production). Create a config module that: loads environment variables from .env files (.env, .env.local, .env.staging, .env.production) with proper precedence, validates all required variables at startup (fail fast with clear error messages listing all missing variables, not just the first one), provides typed access to config values, redacts sensitive values in logs, and includes a CLI command to verify the current environment config. Include a .env.example file with all variables documented.