# Deploying an Express App — Express.js Fundamentals: Routing, Middleware and APIs

Source: https://www.skillbyai.com/en/expressjs/ex-deployment

> Prepare Express for production with NODE_ENV, PORT, a process manager and platform hosting.

## The checklist

Set `NODE_ENV=production`, load secrets from environment variables, listen on `process.env.PORT`, and put a reverse proxy (nginx, or the platform's own) in front.

## Keep it alive

Use a process manager like **PM2**, or let a platform (Render, Railway, Fly.io) manage restarts — plain `node server.js` dies on any uncaught crash.

## Final quiz 1 of 8

Final quiz

**Quiz:** What is Express middleware?

- [ ] A database
- [ ] A template
- [x] A function (req, res, next) that runs during a request
- [ ] A CSS file

*Answer:* A function (req, res, next) that runs during a request. Middleware inspects requests and calls next.

## Final quiz 2 of 8

Final quiz

**Quiz:** Where do route parameters like :id appear?

- [ ] req.query
- [ ] req.body
- [ ] req.headers
- [x] req.params

*Answer:* req.params. Colon segments are captured into req.params.

## Final quiz 3 of 8

Final quiz

**Quiz:** Which middleware parses JSON bodies?

- [x] express.json()
- [ ] express.static()
- [ ] express.Router()
- [ ] cors()

*Answer:* express.json(). Without it req.body is undefined.

## Final quiz 4 of 8

Final quiz

**Quiz:** How many arguments does error middleware take?

- [ ] 2
- [x] 4
- [ ] 3
- [ ] 1

*Answer:* 4. (err, req, res, next) identifies an error handler.

## Final quiz 5 of 8

Final quiz

**Quiz:** Which status code suits invalid input?

- [ ] 200
- [ ] 500
- [x] 400
- [ ] 301

*Answer:* 400. 400 Bad Request signals a client error.

## Final quiz 6 of 8

Final quiz

**Quiz:** What does express.Router help with?

- [ ] Parsing forms
- [ ] Hashing passwords
- [ ] Serving fonts
- [x] Organizing routes into modular files

*Answer:* Organizing routes into modular files. Routers mount groups of routes under a prefix.

## Final quiz 7 of 8

Final quiz

**Quiz:** Who enforces CORS restrictions?

- [x] The browser
- [ ] The database
- [ ] Express
- [ ] The OS

*Answer:* The browser. Servers send headers; browsers decide.

## Final quiz 8 of 8

Final quiz

**Quiz:** Why export app without calling listen for tests?

- [ ] It is faster to write
- [x] supertest can use the app without opening a port
- [ ] listen is deprecated
- [ ] It enables HTTPS

*Answer:* supertest can use the app without opening a port. Tests import the app and make in-process requests.
