What is the main purpose of the app.js file in an Express application?
The app.js file sets up the Express app, configures middleware, routes, and error handling. It is the central place where the app is created and configured.
Click to reveal answer
beginner
Why do Express apps often have a routes folder?
The routes folder organizes route handlers by grouping related URL paths and their logic. This keeps the code clean and easier to maintain.
Click to reveal answer
intermediate
What is the role of middleware in Express application structure?
Middleware functions run during the request-response cycle. They can modify requests, responses, or end the cycle. Middleware helps add features like logging, parsing, and authentication.
Click to reveal answer
beginner
How does the public folder fit into an Express app structure?
The public folder holds static files like images, CSS, and JavaScript that the browser can access directly. Express serves these files using built-in middleware.
Click to reveal answer
beginner
What is the purpose of the views folder in an Express app?
The views folder contains template files that generate HTML dynamically. These templates are rendered by the app to send web pages to users.
Click to reveal answer
Which file usually starts the Express server?
Aserver.js
Bapp.js
Croutes.js
Dindex.html
✗ Incorrect
The server.js file typically imports the app and starts the server listening on a port.
Where should you put your route definitions in an Express app?
AIn the <code>node_modules</code> folder
BIn the <code>public</code> folder
CIn the <code>views</code> folder
DIn the <code>routes</code> folder
✗ Incorrect
Routes are organized in the routes folder to keep the app structure clean.
What does middleware do in Express?
AHandles HTTP requests and responses
BStores static files
CCreates HTML templates
DManages database connections
✗ Incorrect
Middleware functions process requests and responses during the app's request-response cycle.
Which folder contains static assets like images and CSS?
Aviews
Broutes
Cpublic
Dconfig
✗ Incorrect
The public folder holds static files served directly to the browser.
What is the purpose of the views folder?
ATo store route handlers
BTo store template files for rendering HTML
CTo store static files
DTo store middleware functions
✗ Incorrect
The views folder contains templates that generate HTML pages dynamically.
Describe the typical folder structure of an Express application and the role of each main folder.
Think about where you put code for routes, templates, and static files.
You got /5 concepts.
Explain how middleware fits into the Express application structure and why it is important.
Middleware is like helpers that run between receiving a request and sending a response.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the app.js file in an Express application?
easy
A. To set up the Express server, middleware, and routes
B. To store database connection details only
C. To write frontend HTML code
D. To handle user authentication exclusively
Solution
Step 1: Understand the role of app.js
The app.js file is the main entry point where the Express server is created and configured.
Step 2: Identify what app.js typically contains
It usually sets up middleware, routes, and starts the server listening on a port.
Final Answer:
To set up the Express server, middleware, and routes -> Option A
Quick Check:
Main server setup = C [OK]
Hint: Remember: app.js is the main server setup file [OK]
Common Mistakes:
Confusing app.js with frontend files
Thinking app.js only handles database
Assuming app.js is for authentication only
2. Which of the following is the correct way to import the Express module and create an app instance in app.js?
easy
A. import app from 'express'; const express = app();
B. import express from 'express'; const app = express();
C. const app = require('express');
D. const express = require('express'); const app = express();
Solution
Step 1: Recall common Express import syntax
Express is commonly imported using CommonJS syntax: const express = require('express');
Step 2: Create app instance correctly
The app instance is created by calling express(), so const app = express(); is correct.
Why does visiting http://localhost:3000/home return a blank page?
medium
A. Because the route handler is not properly defined or not reached
B. Because the server is not listening on port 3000
C. Because the middleware to parse requests is missing
D. Because res.send is missing a return statement
Solution
Step 1: Check if route handler is correct
The route /home is defined with app.get and sends a response.
Step 2: Consider possible reasons for blank response
If the page is blank, it usually means the route handler is not reached or overridden by other middleware or routes.
Final Answer:
Because the route handler is not properly defined or not reached -> Option A
Quick Check:
Blank page means route not reached = D [OK]
Hint: Blank page usually means route handler not reached [OK]
Common Mistakes:
Thinking res.send needs return statement
Assuming server not listening without error
Confusing missing middleware with route handling
5. You want to organize your Express app by separating routes into different files. Which structure correctly shows how to use a separate users.js route file inside a routes folder and mount it in app.js?
hard
A. // In routes/users.js
const router = require('express.Router')();
router.get('/', (req, res) => res.send('Users list'));
module.exports = router;
// In app.js
app.use('/users', require('./routes/users'));
B. // In routes/users.js
module.exports = (req, res) => res.send('Users list');
// In app.js
app.use('/users', require('./routes/users'));
C. // In routes/users.js
const express = require('express');
const router = express.Router();
router.get('/', (req, res) => res.send('Users list'));
module.exports = router;
// In app.js
const usersRouter = require('./routes/users');
app.use('/users', usersRouter);
D. // In routes/users.js
const express = require('express');
const router = express.Router;
router.get('/', (req, res) => res.send('Users list'));
module.exports = router;
// In app.js
const usersRouter = require('./routes/users');
app.use('/users', usersRouter);
Solution
Step 1: Check correct router creation in users.js
The router should be created with express.Router(), not express() or other calls.
Step 2: Verify correct export and mounting in app.js
The router is exported with module.exports and mounted with app.use('/users', usersRouter);.
Final Answer:
Using express.Router() in the route file and proper mounting -> Option C
Quick Check:
Use express.Router() and app.use() = A [OK]
Hint: Use express.Router() in route files and mount with app.use() [OK]
Common Mistakes:
Using express() instead of express.Router() for router
Exporting a function instead of a router object
Not mounting the router with app.use() properly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.