Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does routing requests manually mean in Node.js?
It means writing code to check the URL and HTTP method of incoming requests and then deciding what response to send back, without using any routing libraries.
Click to reveal answer
beginner
Which Node.js module is commonly used to create a server for manual routing?
The built-in http module is used to create a server that listens for requests and allows manual routing by inspecting the request URL and method.
Click to reveal answer
beginner
How do you check the URL path of a request in manual routing?
You use req.url to get the path and then compare it with strings like '/' or '/about' to decide what to do.
Click to reveal answer
intermediate
Why is it important to check the HTTP method (GET, POST, etc.) in manual routing?
Because the same URL can have different actions depending on the method. For example, GET /users might fetch users, while POST /users might add a new user.
Click to reveal answer
beginner
What is a simple way to send a response back to the client in manual routing?
Use res.writeHead() to set status and headers, then res.end() to send the response body and finish the request.
Click to reveal answer
Which Node.js property holds the URL path of an incoming request?
Ares.path
Bres.url
Creq.path
Dreq.url
✗ Incorrect
req.url contains the URL path of the request.
What Node.js module do you use to create a server for manual routing?
Apath
Bfs
Chttp
Durl
✗ Incorrect
The http module creates servers that handle requests.
Why check the HTTP method in routing?
ATo know what action to perform for the same URL
BTo get the client's IP address
CTo set cookies
DTo close the connection
✗ Incorrect
The method tells if the request is to get data, send data, update, or delete.
Which method sends the response body and ends the response?
Ares.end()
Bres.write()
Cres.send()
Dres.close()
✗ Incorrect
res.end() sends the response and closes the connection.
What is the first step in manual routing inside the server callback?
ASend a response immediately
BCheck <code>req.url</code> and <code>req.method</code>
CClose the server
DImport a routing library
✗ Incorrect
You must check the URL and method to decide how to respond.
Explain how you would handle a GET request to '/' and a POST request to '/submit' manually in Node.js.
Think about checking URL and method inside the server callback.
You got /4 concepts.
Describe why manual routing might be harder than using a routing library and when it could still be useful.
Consider pros and cons of manual vs library routing.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of checking req.url in a Node.js server without frameworks?
easy
A. To decide how to respond to different request paths
B. To parse the request body automatically
C. To connect to a database
D. To handle user authentication
Solution
Step 1: Understand the role of req.url
req.url contains the path requested by the client, like '/home' or '/about'.
Step 2: Purpose of checking req.url
By checking req.url, the server can decide which content or response to send back.
Final Answer:
To decide how to respond to different request paths -> Option A
Quick Check:
Routing = Check req.url [OK]
Hint: Check req.url to route requests manually [OK]
Common Mistakes:
Thinking req.url parses request body
Confusing req.url with database connection
Assuming req.url handles authentication
2. Which of the following is the correct way to send a plain text response with status 200 in a manual Node.js server?
easy
A. res.status(200).send('Hello');
B. res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello');
C. res.sendStatus(200).send('Hello');
D. res.write(200, 'Hello');
Solution
Step 1: Identify correct methods for manual response
In manual Node.js servers, res.writeHead() sets status and headers, res.end() sends the response body.
Step 2: Check each option
res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello'); uses writeHead and end correctly. The second and third options use Express methods, not native Node.js. res.write(200, 'Hello'); is invalid syntax.
Final Answer:
res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello'); -> Option B
Quick Check:
Manual response = writeHead + end [OK]
Hint: Use writeHead and end to send manual responses [OK]
Common Mistakes:
Using Express methods in plain Node.js
Calling res.write without headers
Incorrect method names like res.sendStatus
3. What will the following Node.js server code output when a client requests /hello?