wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Express.js and REST Worksheet — Grade 13

Total questions: 66

Worksheet time: 33mins

Name
Class
Date
1.

Which HTTP method is used to update an existing resource?

(a)  

2.

Chained route handlers for the same route path in Express can be created by using

(a)  

3.

What is the main goal of middleware in Express?

(a)  

4.

Which command creates a package.json file with default values?

(a)  

5.

How to define a dynamic route in Express?

(a)  

6.

Part 1 — Multiple Correct Answers: What statements are correct about the fs module?

a)

Can read files asynchronously

b)

Can write files to disk

7.

Part 1 — Multiple Correct Answers: What are the REST architectural constraints?

a)

Uniform interface

b)

Code on demand

c)

Statelessness

8.

Part 1 — Multiple Correct Answers: Which of the following are types of middleware in Express?

a)

Application-level middlewares

b)

Error-handling middlewares

c)

Router-level middlewares

9.

Part 1 — Multiple Correct Answers: Which statements about Express Router are correct?

a)

Modularizes routes

b)

Can be mounted using app.use()

c)

Supports middleware

10.

Which are valid use cases for a middleware in Express?

(a)  

11.

Part 2 — RESTful API Question: In a RESTful API for a Library system, which URL/Method combinations make sense?

a)

GET /books (To see all books)

b)

DELETE /books/:id (To remove a specific book)

c)

POST /books (To create a new book)

d)

PUT /books (To delete all books) — incorrect; PUT is for updating a resource, not deleting all books

12.

Part 3 — Short Code Questions: Write the command to install the nodemon package as a global package.

(a)  

13.

Part 3 — Short Code Questions: Write the line of code to export a function named add from a file using CommonJS syntax.

(a)  

14.

Part 3 — Short Code Questions: How do you access a dynamic URL parameter with the name “id” inside an Express route?

(a)  

15.

Part 3 — Short Code Questions: Write the line of code to serve a static folder named “public” using Express.

(a)  

16.

Part 3 — Short Code Questions: Write an express method chaining an HTTP status code for Not Found with a response body.

(a)  

17.

Part 4 — Fill in Blanks: Middleware that parses JSON payloads called

(a)  

18.

Part 4 — Fill in Blanks: HTTP Method to modify the resource is

(a)  

19.

Part 4 — Fill in Blanks: Identifier for a resource (e.g., /api/users).

(a)  

20.

HTTP Status code for successful creation is

(a)  

21.

Built-in Node.js module for creating a server.

(a)  

22.

Part 3 (другой вариант) — Short One-Line Code Questions: Write code to define a POST route for /api/products.

(a)  

23.

Part 3 (другой вариант) — Short One-Line Code Questions: Write code to define a middleware that logs the request method and URL for an Express router.

(a)  

24.

Part 3 (другой вариант) — Short One-Line Code Questions: How do you access a query parameter named sort inside an Express route?

(a)  

25.

Part 3 (другой вариант) — Short One-Line Code Questions: Write code to parse JSON data in Express using middleware.

(a)  

26.

Part 3 (другой вариант) — Short One-Line Code Questions: Define a GET route /about that sends back the about.html file.

(a)  

27.

Part 4 (другой вариант) — HTTP Status Codes: A client successfully sends a POST request to /api/products, and the product is created in the database.

(a)  

28.

Part 4 (другой вариант) — HTTP Status Codes: A client sends a GET request to /api/profile without being authenticated, and authentication middleware blocks the request.

(a)  

29.

A client sends a DELETE request to /api/orders/55, and the order is successfully removed. Which HTTP status code should the server return?

a)

204 No Content

b)

200 OK

c)

404 Not Found

d)

503 Service Unavailable

30.

A client sends a GET request to /api/cart, but the route does not exist in the Express application. Which HTTP status code should the server return?

a)

404 Not Found

b)

400 Bad Request

c)

301 Moved Permanently

d)

503 Service Unavailable

31.

A client sends a request to an Express server that is temporarily down for maintenance. Which HTTP status code should the server return?

a)

503 Service Unavailable

b)

500 Internal Server Error

c)

404 Not Found

d)

302 Found

32.

Which engine does Node.js use to execute JavaScript?

a)

SpiderMonkey

b)

Chrome V8

c)

Java HotSpot

d)

Nashorn

33.

In the terminal, what happens when you press Ctrl + C (cmd + C)?

a)

Clears the screen

b)

Stops the execution

c)

Opens a new shell

d)

Pauses the process without terminating

34.

What is the use of dotenv in Node.js applications?

a)

Compile TypeScript to JavaScript

b)

Manage environmental variables

c)

Handle HTTP routing

d)

Run unit tests

35.

Which of the following is NOT true about REST APIs?

a)

REST APIs must use JSON exclusively.

b)

REST can use different representations like XML, YAML, or plain text.

c)

REST is based on stateless communication.

d)

Resources are identified by URLs and manipulated via standard HTTP methods.

36.

Which Node.js core module is used to read and write files?

a)

http

b)

fs

c)

path

d)

url

37.

In an Express route, which object contains route variables like the user id in /users/123?

a)

req.query

b)

req.params

c)

req.body

d)

res.locals

38.

Which of the following are differences between the Browser and Node.js environments? Select all that apply.

a)

Browsers have the window object; Node.js has global.

b)

Node.js can access the local filesystem; Browsers generally cannot.

c)

Sub-environments have access to the document object (DOM).

d)

Node.js allows you to choose your version; Browsers are controlled by the user.

39.

What information is typically contained in an HTTP Request? Select all that apply.

a)

HTTP Method

b)

Request Headers

c)

The Server’s RAM capacity

d)

Request Body

40.

What are the characteristics of the Node.js Event Loop? Select all that apply.

a)

It’s single-threaded.

b)

Performs blocking I/O by default.

c)

Offloads tasks to the system kernel when possible.

d)

Allows for non-blocking I/O operations.

41.

Which of these are valid built-in Express middleware? Select all that apply.

a)

express.json()

b)

express.static()

c)

express.routes()

d)

express.urlencoded()

42.

Which features are provided by the Multer middleware? Select all that apply.

a)

Handling multipart/form-data used for file uploads

b)

Sending emails with attachments

c)

Validating uploaded files’ size and type

d)

Automatically saving files to disk or memory

43.

Which npm commands or files help ensure reproducible builds? Select all that apply.

a)

package-lock.json

b)

node_modules folder

c)

npm update

d)

npm install

44.

What is correct about Node.js EventEmitter class? Select all that apply.

a)

Every object in Node.js inherits from EventEmitter.

b)

Listeners can be added using on or once methods.

c)

Allows you to create, emit, and listen for custom events.

d)

It’s used to handle HTTP requests.

45.

Which of the following are Node.js global objects or classes? Select all that apply.

a)

Buffer

b)

console

c)

process

d)

env

46.

What is right about the events core module? Select all that apply.

a)

Provides the EventEmitter class

b)

Allows asynchronous event-driven programming

c)

Automatically manages HTTP sessions

d)

Not built-in and needs installation

47.

Which statements about middleware in Express are correct? Select all that apply.

a)

Can modify the request and response objects

b)

Must always send a response

c)

Can be chained using next()

d)

Executes after the response is sent

48.

Choose the correct Express route that extracts the id parameter from /users/:id and responds with JSON { userId: }.

a)

app.get('/users/:id', (req, res) => { res.json({ userId: req.params.id }); });

b)

app.get('/users', (req, res) => { res.json({ userId: req.query.id }); });

c)

app.post('/users/:id', (req, res) => { res.send(req.params.id); });

d)

app.get('/users/:id', (req, res) => { res.send({ id: req.body.id }); });

49.

Choose the correct GET route that responds from /api/users with JSON { users: [] }.

a)

app.get('/api/users', (req, res) => { res.json({ users: [] }); });

b)

app.post('/api/users', (req, res) => { res.json({ users: [] }); });

c)

app.get('/api/users', (req, res) => { res.send([]); });

d)

app.get('/users', (req, res) => { res.json({ users: [] }); });

50.

Choose the middleware that logs the HTTP method and URL for each incoming request.

a)

app.use((req, res, next) => { console.log(` req.method{req.method} {req.url}`); next(); });

b)

app.use((req, res) => { console.log(req.body); });

c)

app.get('*', (req, res) => { console.log(req.method); });

d)

app.use((req, res, next) => { next(); console.log(` req.method{req.method} {req.url}`); });

51.

Declare a permanent redirection from old route /profile to new route /dashboard in Express. Select the snippet that performs a 301 redirect from /profile to /dashboard.

a)

js app.get('/profile', (req, res) => { res.redirect(301, '/dashboard'); });

b)

js app.get('/dashboard', (req, res) => { res.redirect('/profile'); });

c)

js app.use('/profile', (req, res) => { res.redirect(302, '/dashboard'); });

d)

js app.get('/profile', (req, res) => { res.redirect('/dashboard'); });

52.

Write an Express error-handling middleware that logs the error and sends a response with “Internal Server Error”. Choose the correct middleware signature and response.

a)

js app.use((err, req, res, next) => { console.error(err); res.status(500).send('Internal Server Error'); });

b)

js app.use((req, res, next) => { console.error('error'); res.status(500).json({ error: 'Internal Server Error' }); });

c)

js app.get((err, req, res, next) => { console.log(err); res.sendStatus(404); });

d)

js app.use((err, req, res) => { res.status(500).send(err); });

53.

Write code to start an Express server on port 5000. Select the snippet that listens on port 5000 and logs a startup message.

a)

js app.listen(5000, () => { console.log('Server running on port 5000'); });

b)

js app.start(5000, () => { console.log('Server started'); });

c)

js app.listen(process.env.PORT, () => { console.log('Server running'); });

d)

js app.listen(3000); console.log('Server running on port 5000');

54.

Write a command to run a script named test from package.json.

(a)  

55.

Write code to read an environment variable named PORT.

(a)  

56.

Write one line to parse URL-encoded form data in Express.

(a)  

57.

You want to design an API endpoint that retrieves data from the server without modifying anything. Fill in the HTTP method.

(a)  

58.

A client sends data to the server to create a new resource. Fill in the HTTP method.

(a)  

59.

If a client wants to remove a resource identified by its ID. Fill in the HTTP method.

(a)  

60.

A client needs to modify only certain fields of a resource without replacing the entire resource. Fill in the HTTP method.

(a)  

61.

When a client wants to replace an entire existing resource with new data. Fill in the HTTP method.

(a)  

62.

A valid request is sent to the server, but the database connection fails unexpectedly during processing. Fill in the appropriate HTTP status.

(a)  

63.

A client sends a PUT request to /api/users but the API only supports GET and POST for this endpoint. Fill in the appropriate HTTP status.

(a)  

64.

A client sends a GET request to /api/orders/101 but no order with that ID exists in the database. Fill in the appropriate HTTP status.

(a)  

65.

A logged-in user attempts to access DELETE /api/users/7 but doesn't have administrator privileges. Fill in the appropriate HTTP status.

(a)  

66.

A client sends a POST request to /login without a password field. The server cannot process the request due to missing required data. Fill in the appropriate HTTP status.

(a)