MEAN MEAN Stack Security and Deployment 2 — Questions and Answers
Question 1: What is Docker and how does it benefit MEAN stack application deployment?
- Containerizes each application component (Node, MongoDB, Angular) for consistent, portable deployments (Correct answer)
- A database management system for containerized MongoDB instances
- A CI/CD pipeline tool for deploying MEAN stack applications
- A reverse proxy for routing traffic to Node.js servers
Correct answer: Containerizes each application component (Node, MongoDB, Angular) for consistent, portable deployments
Docker packages applications with their dependencies into containers that run consistently across development, staging, and production environments, eliminating 'works on my machine' issues.
Question 2: What is Nginx commonly used for in a production MEAN stack deployment?
- Reverse proxy that forwards requests to Node.js, serves Angular static files, and handles SSL termination (Correct answer)
- A Node.js alternative for serving the Express API
- A MongoDB administration and monitoring interface
- A container orchestration tool for MEAN stack services
Correct answer: Reverse proxy that forwards requests to Node.js, serves Angular static files, and handles SSL termination
Nginx acts as a reverse proxy, receiving all incoming traffic, serving the Angular build's static files directly, forwarding API requests to Express, and terminating SSL.
Question 3: What does the `npm run build` command do for an Angular application?
- Compiles TypeScript, bundles modules, optimizes assets, and outputs static files to the dist/ folder (Correct answer)
- Runs the Angular development server with live reload
- Installs all npm dependencies from package.json
- Runs unit tests and generates a code coverage report
Correct answer: Compiles TypeScript, bundles modules, optimizes assets, and outputs static files to the dist/ folder
ng build (triggered by npm run build) compiles Angular TypeScript, performs tree-shaking, minification, and code splitting, outputting optimized static files for production deployment.
Question 4: What is CI/CD in the context of MEAN stack development?
- Continuous Integration automatically tests code changes; Continuous Deployment automatically deploys passing builds (Correct answer)
- Code Inspection and Container Deployment tools for Node.js
- Configuration Injection and Cache Dependency management
- Commit Integration and Code Distribution for team workflows
Correct answer: Continuous Integration automatically tests code changes; Continuous Deployment automatically deploys passing builds
CI/CD pipelines automatically run tests on every commit (CI) and deploy the application to staging or production when tests pass (CD), reducing manual deployment risk.
Question 5: What is the purpose of a `.env` file in a MEAN stack Node.js project?
- Stores environment-specific configuration and secrets locally without committing them to version control (Correct answer)
- Defines npm scripts and environment setup commands
- Configures the Node.js runtime environment and version
- Sets Angular environment variables for the frontend build
Correct answer: Stores environment-specific configuration and secrets locally without committing them to version control
.env files store secrets like MongoDB URIs, JWT secrets, and API keys using dotenv; they must be in .gitignore to prevent accidentally committing credentials.
Question 6: What is horizontal scaling and how does it apply to a MEAN stack API?
- Adding more server instances behind a load balancer to handle increased traffic (Correct answer)
- Adding more CPU and RAM to the existing server
- Adding more MongoDB replica set members for read scaling
- Increasing Node.js worker thread count per server
Correct answer: Adding more server instances behind a load balancer to handle increased traffic
Horizontal scaling runs multiple identical Node.js/Express instances behind a load balancer, distributing traffic across them to handle more concurrent requests.
What is Docker and how does it benefit MEAN stack application deployment?