Bird
Raised Fist0
Expressframework~20 mins

Express installation and setup - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. What command do you use to install Express in a Node.js project?
easy
A. npm install express
B. node install express
C. express install
D. npm start express

Solution

  1. Step 1: Understand Node.js package installation

    Node.js packages are installed using the npm tool with the command npm install <package-name>.
  2. Step 2: Identify the correct package name for Express

    The package name for Express is exactly "express", so the command is npm install express.
  3. Final Answer:

    npm install express -> Option A
  4. Quick Check:

    Express installation command = npm install express [OK]
Hint: Use npm install followed by package name [OK]
Common Mistakes:
  • Using 'node install' instead of 'npm install'
  • Typing 'express install' which is invalid
  • Trying to start express with npm start express
2. Which of the following is the correct way to import Express and create an app instance?
easy
A. const express = require('express'); const app = express();
B. import express from 'express'; const app = express();
C. const app = require('express'); app = express();
D. const express = import('express'); const app = express();

Solution

  1. Step 1: Recognize CommonJS import syntax

    In many Node.js projects, Express is imported using CommonJS syntax: const express = require('express');.
  2. Step 2: Create app instance correctly

    After importing, the app instance is created by calling express(), so const app = express(); is correct.
  3. Final Answer:

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

    Import Express and create app = require + express() [OK]
Hint: Use require('express') then call express() [OK]
Common Mistakes:
  • Using import without proper module setup
  • Calling require('express')() directly without variable
  • Using import as a function
3. What will the following code do when run?
const express = require('express');
const app = express();
app.get('/', (req, res) => res.send('Hello World'));
app.listen(3000, () => console.log('Server started'));
medium
A. Start a server but does not respond to any requests
B. Throw an error because app.listen is missing a callback
C. Respond with 'Hello World' without starting a server
D. Start a server on port 3000 that responds with 'Hello World' at root URL

Solution

  1. Step 1: Analyze server setup and route

    The code creates an Express app, sets a GET route for '/' that sends 'Hello World'.
  2. Step 2: Understand app.listen behavior

    The server listens on port 3000 and logs 'Server started' when ready, so it starts correctly.
  3. Final Answer:

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

    Express server with route '/' = Hello World response [OK]
Hint: app.listen starts server; app.get defines response [OK]
Common Mistakes:
  • Thinking app.listen needs a callback to work
  • Assuming no response because of missing middleware
  • Confusing route setup with server start
4. Identify the error in this Express setup code:
const express = require('express');
const app = express;
app.listen(3000);
medium
A. app.listen needs a callback function
B. Missing parentheses when creating app instance
C. express should be imported with import, not require
D. app.listen requires a port number as a string

Solution

  1. Step 1: Check app instance creation

    The code assigns app = express without calling it. It should be express() to create the app instance.
  2. Step 2: Verify app.listen usage

    Calling app.listen(3000) is correct; port number is a number, and callback is optional.
  3. Final Answer:

    Missing parentheses when creating app instance -> Option B
  4. Quick Check:

    express() must be called to create app [OK]
Hint: Remember to call express() with parentheses [OK]
Common Mistakes:
  • Assigning app = express instead of app = express()
  • Passing port as string instead of number (allowed but not required)
  • Thinking callback in listen is mandatory
5. You want to create an Express server that listens on port 8080 and responds with 'Welcome!' at the root URL. Which code snippet correctly does this?
hard
A. const express = require('express'); const app = express(); app.listen(8080, () => console.log('Server running'));
B. const express = require('express'); const app = express; app.get('/', (req, res) => res.send('Welcome!')); app.listen(8080);
C. const express = require('express'); const app = express(); app.get('/', (req, res) => res.send('Welcome!')); app.listen(8080);
D. const express = require('express'); const app = express(); app.get('/', (req, res) => res.send('Welcome!')); app.listen('3000');

Solution

  1. Step 1: Create app instance correctly

    Use const app = express(); to create the Express app instance.
  2. Step 2: Define route and start server on port 8080

    Set up app.get('/', ...) to respond with 'Welcome!' and call app.listen(8080); to start the server.
  3. Final Answer:

    const express = require('express'); const app = express(); app.get('/', (req, res) => res.send('Welcome!')); app.listen(8080); -> Option C
  4. Quick Check:

    Express app with route and listen on 8080 = const express = require('express'); const app = express(); app.get('/', (req, res) => res.send('Welcome!')); app.listen(8080); [OK]
Hint: Call express(), define route, then listen on port [OK]
Common Mistakes:
  • Not calling express() to create app
  • Passing port as string instead of number (allowed but inconsistent)
  • Starting server without defining route
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