Loading

Quipoin Menu

Learn • Practice • Grow

express-js / Your First Express Server
mcq
Direction: Choose the correct option

Q1.

What is the minimal code to create a simple Express server that responds with 'Hello World' at the root?
A. const express = require('express'); const app = express(); app.use('/', (req, res) => res.send('Hello World')); app.listen(3000);
B. const express = require('express'); const app = express(); app.get('/', (req, res) => res.send('Hello World')); app.listen(3000);
C. const express = require('express'); express().get('/', (req, res) => res.send('Hello World')).listen(3000);
D. const app = express(); app.get('/', (req, res) => res.send('Hello World')); app.listen(3000);
Direction: Choose the correct option

Q2.

In the callback of app.get('/', (req, res) => { ... }), what do req and res represent?
A. Query and result
B. Router and server
C. Request and response objects
D. Input and output
Direction: Choose the correct option

Q3.

What happens if you do not call any method like res.send() in a route handler?
A. An error is thrown
B. The next middleware is called automatically
C. The request hangs and eventually times out
D. The server sends a default response
Direction: Choose the correct option

Q4.

How can you make your server listen on a dynamic port (e.g., from environment variables)?
A. app.listen(3000);
B. app.listen(process.env.PORT);
C. app.listen(env.PORT);
D. const port = process.env.PORT || 3000; app.listen(port);
Direction: Choose the correct option

Q5.

Which method is used to log a message when the server starts listening?
A. app.start(3000, () => console.log('Server running'));
B. Both A and B
C. app.on('listening', () => console.log('Server running'));
D. app.listen(3000, () => console.log('Server running'));