Loading

Quipoin Menu

Learn • Practice • Grow

express-js / Express.js Serving Dynamic Content
interview

Q1. How do you serve dynamic content in Express?
Dynamic content is generated on the server, often using templating engines. You fetch data from a database or external API, then pass it to a template with res.render(). Alternatively, you can send JSON responses for client-side rendering (SPAs).

Q2. What is the difference between server-side and client-side rendering?
Server-side rendering (SSR) generates HTML on the server for each request (using templates). Client-side rendering (CSR) sends a minimal HTML and JavaScript, and the client builds the UI. Express can do both: SSR with templates, or serve API data for CSR.

Q3. How do you send dynamic JSON responses?
Use res.json() with JavaScript objects. Example: app.get('/api/users', (req, res) => { const users = [{id:1, name:'John'}]; res.json(users); }). This is common for REST APIs where the frontend handles rendering.

Q4. How do you combine static and dynamic content?
You can have static files (CSS, images) served via express.static, while routes generate dynamic HTML with templates. In your EJS file, you reference static files: .

Q5. What is res.locals used for?
res.locals is an object that contains response-local variables scoped to the request. Data placed here is available to templates rendered during that request-response cycle. It's useful for passing middleware data (like authenticated user) to views.
"