0
0
Expressframework~20 mins

Express installation and setup - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Express Setup Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
1:00remaining
Identify the correct command to install Express locally
Which command correctly installs Express as a local dependency in your Node.js project?
Anpm install express
Bnpm install -g express
Cnpm add express
Dnode install express
Attempts:
2 left
💡 Hint
Think about installing packages for your project, not globally.
component_behavior
intermediate
1:30remaining
What happens when you run this Express setup code?
Given the following Express app code, what will be the output when you visit http://localhost:3000/ in a browser?
Express
import express from 'express';
const app = express();
app.get('/', (req, res) => {
  res.send('Hello World!');
});
app.listen(3000);
AThe browser shows the text 'Hello World!'
BThe browser shows a 404 Not Found error
CThe server crashes with an error
DThe browser shows a blank page
Attempts:
2 left
💡 Hint
Check the route and response sent by the server.
🔧 Debug
advanced
2:00remaining
Why does this Express app fail to start?
Consider this Express app code snippet. Why does running it cause an error?
Express
const express = require('express')
const app = express()
app.get('/', (req, res) => {
  res.send('Hi')
})
app.listen(3000
ANo error, app runs fine
BReferenceError because express is not imported correctly
CTypeError because res.send is not a function
DSyntaxError due to missing closing parenthesis in app.listen
Attempts:
2 left
💡 Hint
Check the parentheses in the last line carefully.
🧠 Conceptual
advanced
1:30remaining
What is the purpose of the 'express()' function call?
In Express, what does calling express() do?
AStarts the server listening on a port
BCreates an Express application instance to handle requests and responses
CImports the Express library into the project
DDefines a route handler for incoming requests
Attempts:
2 left
💡 Hint
Think about what you need before defining routes or starting the server.
state_output
expert
2:00remaining
What is the value of 'port' after running this code?
Given this Express setup code, what is the value of the variable port after execution?
Express
import express from 'express';
const app = express();
const port = process.env.PORT || 3000;
app.listen(port);
AUndefined because process.env.PORT is not set
BAlways 3000 regardless of environment variables
C3000 if no PORT environment variable is set, otherwise the value of PORT
DThrows an error because process.env is not defined
Attempts:
2 left
💡 Hint
Check how the logical OR operator works in JavaScript.