Bird
Raised Fist0
Expressframework~20 mins

What is Express - Practice Questions & Exercises

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Express Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is Express used for in Node.js?

Express is a popular framework in Node.js. What is its main purpose?

ATo style web pages with CSS
BTo manage databases and perform SQL queries
CTo create web servers and handle HTTP requests easily
DTo compile JavaScript into machine code
Attempts:
2 left
💡 Hint

Think about what web servers do and how Express helps with that.

❓ component_behavior
intermediate
2:00remaining
What does this Express code output when accessed at '/'?

Consider this Express app code. What will a user see when they visit the root URL '/'?

Express
import express from 'express';
const app = express();
app.get('/', (req, res) => {
  res.send('Hello from Express!');
});
app.listen(3000);
AThe browser shows the text: Hello from Express!
BThe browser shows a 404 Not Found error
CThe server crashes with an error
DThe browser shows a blank page
Attempts:
2 left
💡 Hint

Look at the route defined with app.get and what it sends back.

📝 Syntax
advanced
2:00remaining
Which option correctly creates an Express app and starts listening on port 4000?

Choose the code snippet that correctly creates an Express app and starts the server on port 4000 without errors.

A
const express = require('express')
const app = express
app.listen(4000)
B
import express from 'express'
const app = express()
app.listen(4000, () => console.log('Server running'))
C
import express from 'express'
const app = express
app.listen(4000, () => console.log('Server running'))
D
const express = require('express')
const app = express()
app.listen(4000, () => console.log('Server running'))
Attempts:
2 left
💡 Hint

Remember to call the express function to create the app and use correct import syntax for ES modules.

🔧 Debug
advanced
2:00remaining
Why does this Express app crash with 'TypeError: app.get is not a function'?

Look at this code snippet. Why does it crash with the error 'TypeError: app.get is not a function'?

Express
import express from 'express';
const app = express();
app.get('/', (req, res) => res.send('Hi'));
app.listen(3000);
ABecause express is not called as a function to create the app instance
BBecause the route '/' is missing a callback function
CBecause app.listen is missing a port number
DBecause import syntax is incorrect
Attempts:
2 left
💡 Hint

Check how the app variable is assigned from express.

❓ state_output
expert
3:00remaining
What is the output after these Express middleware run in order?

Given this Express app with middleware, what will the client see when requesting '/'?

Express
import express from 'express';
const app = express();

app.use((req, res, next) => {
  req.message = 'Hello';
  next();
});

app.use((req, res, next) => {
  req.message += ' from middleware';
  next();
});

app.get('/', (req, res) => {
  res.send(req.message);
});

app.listen(3000);
AError: req.message is undefined
BHello
Cfrom middleware
DHello from middleware
Attempts:
2 left
💡 Hint

Think about how middleware modifies the request object before the route handler runs.

Practice

(1/5)
1. What is Express in the context of web development?
easy
A. A database management system
B. A programming language like JavaScript
C. A framework to build web servers easily and quickly
D. A tool to design graphics and images

Solution

  1. Step 1: Understand Express purpose

    Express is known as a framework that helps developers create web servers with less code and more speed.
  2. Step 2: Compare options

    Options A, C, and D describe unrelated tools or languages, not Express.
  3. Final Answer:

    A framework to build web servers easily and quickly -> Option C
  4. Quick Check:

    Express = web server framework [OK]
Hint: Express is for web servers, not databases or design tools [OK]
Common Mistakes:
  • Confusing Express with a database
  • Thinking Express is a programming language
  • Mixing Express with design software
2. Which of the following is the correct way to create an Express app in JavaScript?
easy
A. const app = express();
B. const app = new Express();
C. const app = express.createApp();
D. const app = createExpress();

Solution

  1. Step 1: Recall Express app creation syntax

    Express apps are created by calling the express function directly: express()
  2. Step 2: Evaluate each option

    const app = express(); uses the correct syntax. Options B, C, and D use incorrect or non-existent methods.
  3. Final Answer:

    const app = express(); -> Option A
  4. Quick Check:

    Express app creation = const app = express() [OK]
Hint: Remember: express() returns the app instance [OK]
Common Mistakes:
  • Using 'new' keyword with express
  • Calling non-existent methods like createApp
  • Mixing function names incorrectly
3. What will the following Express code do?
const express = require('express');
const app = express();
app.get('/', (req, res) => {
  res.send('Hello World');
});
app.listen(3000);
medium
A. Start a server on port 3000 that responds with 'Hello World' at the root URL
B. Throw an error because app.listen is missing a callback
C. Create a server but does not respond to any requests
D. Start a server that responds with JSON data

Solution

  1. Step 1: Analyze the code behavior

    The code creates an Express app, sets a GET route at '/', and sends 'Hello World' as response.
  2. Step 2: Understand server start and response

    app.listen(3000) starts the server on port 3000. The route handler sends plain text 'Hello World'.
  3. Final Answer:

    Start a server on port 3000 that responds with 'Hello World' at the root URL -> Option A
  4. Quick Check:

    Express route '/' sends 'Hello World' [OK]
Hint: GET '/' route sends 'Hello World' on port 3000 [OK]
Common Mistakes:
  • Thinking app.listen needs a callback
  • Assuming no response is sent
  • Confusing text response with JSON
4. Identify the error in this Express code snippet:
const express = require('express');
const app = express();
app.get('/', (req, res) => {
  res.send('Welcome');
});
app.listen();
medium
A. app.get() requires a second argument to be a string
B. app.listen() is missing the port number
C. express() must be called with 'new' keyword
D. res.send() cannot send strings

Solution

  1. Step 1: Check app.listen usage

    app.listen() requires a port number to start the server. Missing port causes error.
  2. Step 2: Verify other parts

    res.send() can send strings, express() is a function (no 'new'), and app.get() second argument is a function, not string.
  3. Final Answer:

    app.listen() is missing the port number -> Option B
  4. Quick Check:

    app.listen needs port number [OK]
Hint: Always provide a port number to app.listen() [OK]
Common Mistakes:
  • Omitting port in app.listen()
  • Using 'new' with express()
  • Misunderstanding res.send() argument types
5. You want to create a simple API with Express that responds with JSON data at the route '/data'. Which code snippet correctly achieves this?
hard
A. app.get('/data', (req, res) => { res.sendJson({ message: 'Hello' }); });
B. app.post('/data', (req, res) => { res.send('Hello'); });
C. app.route('/data').send({ message: 'Hello' });
D. app.get('/data', (req, res) => { res.json({ message: 'Hello' }); });

Solution

  1. Step 1: Identify correct method for JSON response

    Express provides res.json() to send JSON data properly.
  2. Step 2: Check route and method correctness

    app.get('/data', (req, res) => { res.json({ message: 'Hello' }); }); uses GET method and res.json() correctly. app.post('/data', (req, res) => { res.send('Hello'); }); uses POST and sends string, A uses non-existent res.sendJson(), D uses invalid chaining.
  3. Final Answer:

    app.get('/data', (req, res) => { res.json({ message: 'Hello' }); }); -> Option D
  4. Quick Check:

    Use res.json() for JSON responses [OK]
Hint: Use res.json() to send JSON data in Express [OK]
Common Mistakes:
  • Using res.send() for JSON without conversion
  • Calling non-existent methods like res.sendJson()
  • Incorrect route method or chaining
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard