0
0
Expressframework~20 mins

Express application structure - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Express Structure Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Express route handler?
Consider this Express route handler code. What will the client receive when accessing /hello?
Express
const express = require('express');
const app = express();

app.get('/hello', (req, res) => {
  res.send('Hello, world!');
});

app.listen(3000);
AThe client receives a JSON object { message: 'Hello, world!' }
BThe client receives the text 'Hello, world!'
CThe client receives an empty response
DThe server crashes with an error
Attempts:
2 left
💡 Hint
Look at what the res.send method sends back.
📝 Syntax
intermediate
2:00remaining
Which option correctly sets up a middleware in Express?
You want to add a middleware that logs every request method and URL. Which code snippet correctly does this?
Aapp.use((req, res) => { console.log(req.method, req.url); });
Bapp.addMiddleware((req, res, next) => { console.log(req.method, req.url); next(); });
Capp.middleware((req, res, next) => { console.log(req.method, req.url); next(); });
Dapp.use((req, res, next) => { console.log(req.method, req.url); next(); });
Attempts:
2 left
💡 Hint
Express uses a specific method to add middleware functions.
🔧 Debug
advanced
2:00remaining
Why does this Express app crash on startup?
Examine the code below. Why does the server crash when you run it?
Express
const express = require('express');
const app = express();

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

app.listen(3000);
console.log('Server started');
ATypeError because res.send is called incorrectly
BNo error; server starts normally
CSyntaxError due to missing closing parenthesis in app.listen call
DReferenceError because express is not defined
Attempts:
2 left
💡 Hint
Check the parentheses in the app.listen line.
state_output
advanced
2:00remaining
What is the value of count after these requests?
Given this Express app, what is the value of count after three GET requests to /count?
Express
const express = require('express');
const app = express();
let count = 0;

app.get('/count', (req, res) => {
  count += 1;
  res.send(`Count is ${count}`);
});

app.listen(3000);
A3
B1
C0
DUndefined
Attempts:
2 left
💡 Hint
Each request increases count by 1.
🧠 Conceptual
expert
2:00remaining
Which statement best describes Express app structure?
Which of the following best describes the typical structure of an Express application?
AAn Express app uses modular routing and middleware, separating concerns into different files.
BExpress apps require a database connection in the main file to run.
CExpress apps do not support middleware functions.
DAn Express app is a single file with all routes and middleware defined inline.
Attempts:
2 left
💡 Hint
Think about how to keep code organized and maintainable.