MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Express Application Initialization, Routing & Request/Response Objects0%
Study Materials
Node.js & Express.jsProgress 0%
1.1Node.js Architecture, V8 Engine & Single-Threaded Event Loop1.2Call Stack, Callback Queue, Microtask Queue & Libuv Workers1.3Non-Blocking Asynchronous Code with Promises and Async/Await
3.1Native HTTP Server vs Express Framework Philosophy3.2Express Application Initialization, Routing & Request/Response Objects3.3Route Parameters, Query Strings & Request Body Parsing
HomeTutorialsNode.js & Express.jsExpress Application Initialization, Routing & Request/Response Objects
Route Parameters, Query Strings & Request Body Parsing

Express Application Initialization, Routing & Request/Response Objects

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

The core workflow of any Express application revolves around three pillars: initializing the application instance, registering routes mapped to HTTP verbs, and manipulating the Request (req) and Response (res) objects.


1. Application Initialization and Server Lifecycle

An Express application begins by invoking the top-level express() function exported by the module:

1import express from 'express';
2 
3const app = express();
4const PORT = process.env.PORT || 4000;
5 
6// Register routes here...
7 
8const server = app.listen(PORT, () => {
9 console.log(`Server listening on http://localhost:${PORT}`);
10});
11 
12// Graceful Shutdown handling
13process.on('SIGTERM', () => {
14 console.log('SIGTERM signal received: closing HTTP server');
15 server.close(() => {
16 console.log('HTTP server closed cleanly');
17 });
18});

2. HTTP Verb Routing Methods

Express supports all standard HTTP verbs:

1// GET: Retrieve resource
2app.get('/api/products', (req, res) => {
3 res.json({ products: [] });
4});
5 
6// POST: Create resource
7app.post('/api/products', (req, res) => {
8 res.status(201).json({ message: 'Product created' });
9});
10 
11// PUT: Replace entire resource
12app.put('/api/products/:id', (req, res) => {
13 res.json({ message: `Product ${req.params.id} fully updated` });
14});
15 
16// PATCH: Partial update of resource
17app.patch('/api/products/:id', (req, res) => {
18 res.json({ message: `Product ${req.params.id} partially modified` });
19});
20 
21// DELETE: Remove resource
22app.delete('/api/products/:id', (req, res) => {
23 res.status(204).send(); // 204 No Content
24});

3. The req and res Ecosystem

Express decorates the native Node.js request and response objects with convenient helper properties and methods:

Key req Properties

  • req.method: The HTTP verb (GET, POST, etc.)
  • req.path: The path part of the request URL (e.g., /api/users)
  • req.ip: Client IP address
  • req.headers: Key-value map of incoming HTTP headers
  • req.get(headerName): Case-insensitive header lookup (e.g., req.get('Authorization'))

Key res Methods

  • res.status(code): Sets the HTTP status code (chainable)
  • res.json(data): Sends JSON response with appropriate headers
  • res.send(body): Sends generic HTTP body (HTML, string, or Buffer)
  • res.sendStatus(code): Sets status code and sends its text representation (e.g., res.sendStatus(404) sends "Not Found")
  • res.redirect(url): Performs HTTP 302/301 redirection
  • res.set(field, value): Sets an outgoing HTTP header

Interactive Quiz• Knowledge Check

Multiple Choice Questions

Question 1
Which HTTP status code should be returned when a new resource is successfully created via a POST request?
Question 2
What is the fundamental difference between HTTP PUT and HTTP PATCH methods in RESTful API design?
Question 3
Which method on the Express res object sets the HTTP response code and returns the response in a chainable manner?
Question 4
How can you retrieve the value of the Authorization header safely regardless of whether the client sent it in upper or lowercase?
Question 5
What does res.status(204).send() communicate to the client?

Next Lesson

Route Parameters, Query Strings & Request Body Parsing

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Native HTTP Server vs Express Framework PhilosophyRoute Parameters, Query Strings & Request Body Parsing

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master Node.js & Express.js with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext