Routing Requests and User Input

Duration: 21 min

This video lesson is available to enrolled students.

Return to /learn/BIHAR-STET-COMPUTER-SCIENCE-COMPLETE-COURSE/unit-10-web-development/nodejs/request-response/asset-routing-requests-and-user-input after enrolling

Inside: a video lesson and guided study material.

Module outline

  1. About the course: About the Course
  2. Mathematical Aptitude / गणितीय अभिक्षमता: Number System HCF and LCM Divisibility Rules Percentage Ratio and Proportion Average Profit, Loss and Discount Time and Work Solid Mensuration Simple and Compound Interest Time, Speed and Distance Age Problems Mixture and Alligation Algebra Simplification, Indices and Surds Pipe and Cistern Trigonometry Statistics Data Interpretation Arithmetic Sets, Relations, Functions and Discrete Mathematics Number Systems and Number Theory Coordinate Geometry, Vectors and 3D Geometry Polynomials, Equations and Complex Numbers Euclidean Geometry and Mensuration Trigonometry वास्तविक और सम्मिश्र विश्लेषण Plane Mensuration अनुक्रम, श्रेणी और संयोजन आव्यूह और रैखिक बीजगणित Statistics and Probability Partnership
  3. Logical Reasoning / तार्किक तर्कशक्ति: Series / श्रेणी Coding-Decoding / कूट लेखन एवं कूट वाचन Analogy and Classification Blood Relations Direction and Distance Order and Ranking Non-Verbal Reasoning Seating Arrangement and Puzzles Syllogisms Venn Diagrams, Syllogism and Inequalities Mathematical Operations and Missing Numbers Alphabet and Number Test Statement-Based Reasoning Analytical Reasoning (Counting Figures Reasoning) Cubes, Dice and Figure Counting Calendar and Clock Clock Thinking, Language, Intelligence and Creativity Data Sufficiency and Decision Making Inequality Integers & Rational Numbers
  4. General Knowledge / सामान्य ज्ञान: Scientific Achievements and Research ऊष्मागतिकी एवं साम्यावस्था कोशिका: संरचना एवं कार्य भारतीय राष्ट्रीय आंदोलन एवं स्वतंत्र भारत भारत का भौतिक पर्यावरण भारतीय संविधान भारतीय अर्थव्यवस्था Current Affairs खेल एवं क्रीड़ाएँ State-Specific General Knowledge Agronomy and Farming Systems Agrometeorology Plant Protection Agricultural Economics and Extension Indian Mural Painting Art Criticism, Art Writing and Art Institutions Evolution Biotechnology Periodic Classification and Chemical Bonding d- and f-Block Elements and Coordination Compounds Organic Chemistry: Basic Principles and Isomerism Organic Compounds Containing Oxygen and Nitrogen Consumer Behaviour and Demand National Income Accounting मुद्रा एवं बैंकिंग Inflation and Monetary Policy Public Finance and Government Budget International Economics Cultural and Language Awareness राष्ट्रीय पहचान और महत्वपूर्ण दिवस Books and Publications Awards and Personalities Defence and Security Awareness Atmosphere and Climate Natural Hazards and Disasters जनसंख्या, मानव विकास एवं सांस्कृतिक भूगोल Human Settlements Industries, Services, Transport and Trade प्रादेशिक एवं राजनीतिक भूगोल Prehistoric Cultures and the Harappan Civilisation Delhi Sultanate and the Deccan Kingdoms Mughal Empire and the Marathas संघ सरकार Public Administration and Governance International Relations: Theories and Concepts Society, Community and Social Groups Social Stratification and Inequality आधुनिक हिंदी कविता हिंदी गद्य साहित्य History of English Literature Digital India and Online Services पृथ्वी: उत्पत्ति, आंतरिक संरचना एवं विवर्तनिकी Geomorphic Processes and Landforms Hydrosphere: Oceans Maps, Remote Sensing and Geographical Techniques Production and Costs Determination of Income and Employment द्रव्य एवं रसायन विज्ञान की मूल अवधारणाएँ परमाणु संरचना एवं नाभिकीय रसायन States of Matter and Solutions Redox Reactions and Electrochemistry धातुकर्म, s-ब्लॉक एवं p-ब्लॉक तत्व हाइड्रोकार्बन, हैलोऐल्केन एवं हैलोऐरीन Measurement and Mathematical Methods गति और गति के नियम कार्य, ऊर्जा, शक्ति और घूर्णी गति Gravitation Mechanical Properties of Matter Thermal and Statistical Physics Oscillations and Mechanical Waves Electrostatics and Current Electricity Magnetism, Induction and Alternating Current Optics and Photonics Quantum Physics and Relativity Atoms, Nuclei and Astrophysics Political Science and the State Political Ideologies World Political Thought Indian Political Thought Comparative Politics संघवाद, राज्य और स्थानीय शासन भारतीय राजनीति और जनभागीदारी मानव कार्यिकी Molecular Basis of Inheritance Biology in Human Welfare पारिस्थितिकी एवं पर्यावरण Sources and Historiography Post-Mauryan and Gupta Age Harsha and Early Medieval India European Arrival, British Expansion and 1857 औपनिवेशिक शासन, अर्थव्यवस्था एवं समाज सुधार Modern and Contemporary World Family, Marriage and Kinship Culture, Socialisation and Social Control Sociological Thinkers Modern Sociological Theory Indian Society and Population Social Change and Development Social Problems and Welfare Vegetables and Specialty Crops Floriculture, Landscaping and Protected Cultivation Food and Nutrients Fundamentals, Media and Techniques of Art Buddhist, Jain and Hindu Art Indian Architecture, Temple Sculpture and Bronzes Indian Miniature Painting Schools Folk Art and Crafts World Art: Prehistory to Romanticism Modern Western Art Applied Art and Visual Communication Indian and Western Aesthetics Other Classical Dance Forms Folk and Contemporary Dance Analysis of Financial Statements Business Finance, Banking and Financial Markets Solid State Physics and Electronics Trade, Marketing and Consumer Protection हिंदी कथा साहित्य हिंदी नाटक और कथेतर गद्य Main-group and Periodic Chemistry Society, Law & Ethics
  5. Art of Teaching / शिक्षण कला: Teaching-Learning Process and Classroom Management व्यक्तिगत भिन्नताएँ, क्षमताएँ और व्यक्तित्व अभिप्रेरणा और स्वनिर्देशित अधिगम Teaching Methods and Approaches Microteaching and Classroom Communication Teaching Aids and Educational Technology Assessment and Evaluation Teacher: Qualities, Professional Ethics and Development Educational Policies, Acts and Administration Curriculum, Arts and Co-curricular Areas Guidance and Counselling Education of Children with Disabilities Micro-Teaching & Teaching Skills Lesson Planning शिक्षा, समाज एवं जेंडर समावेशी शिक्षा विज्ञान शिक्षणशास्त्र Social Psychology Data Collection and Measurement शिक्षा का अर्थ, उद्देश्य एवं दर्शन Educational Objectives and Bloom's Taxonomy Educational Psychology Growth and Development Theories of Development Socialisation and Gender Cognitive Processes Mental Health and Guidance Teaching Methods Teaching Aids and Educational Technology Assessment and Evaluation Transformation of Sentences Writing Skills Language, Culture and Nonverbal Signals Listening, Conversation and Communication Skills Mathematics Pedagogy Pedagogy of History Learning Learning and Behavioural Theories Teaching Planning and Teaching Skills Sentence Structure and Common Errors
  6. Environmental Science / पर्यावरण विज्ञान: Environment Biomolecules, Polymers and Everyday Chemistry Geography as a Discipline and Geographical Thought जैवमंडल, मृदा एवं पर्यावरण संसाधन, कृषि, खनिज एवं ऊर्जा Food Science, Processing and Food Safety
  7. Unit 1 | Digital Electronics: Digital Systems & Boolean Basics Logic Gates & Hardware Boolean Expression Boolean Minimization Combinational Circuit Sequential Circuits Number System Number Representation
  8. Unit 2 | COA: Basics of COA Floating Point Rep Cache Memory Organization Input Output Organisation Instr Formats & Modes Control Unit Design Register Transfer and Microoperations Programming the Basic Computer
  9. Unit 3 | C Programming: C Fundamentals Control Flow Functions Arrays & Pointers Storage Classes, Structures & Enums DMA, Macros, Scoping & File Handling
  10. Unit 3 | Data Structures: Introduction to DS Array Stack Queue Linked List Tree Graphs Hashing
  11. Unit 4 | Algorithms: Algorithm Analysis Time Complexity Analysis Sorting Algorithms Dynamic Programming Minimum Spanning Trees Shortest Path Algos Advanced Algorithms
  12. Unit 5 | Operating System: Introduction to OS Process Management CPU Scheduling Process Synchronization Threads & Process Creation Deadlock Memory Management Virtual Memory Disc Scheduling File Management
  13. Unit 6 | Database Management System: Basics of DBMS ER Diagram Relational Model & Functional Dependencies Keys & Integrity Constraints Normalization (1NF - BCNF) Decomposition Properties & 4NF File Organization & Indexing Relational Algebra SQL Transaction Management Concurrency Control
  14. Unit 7 | Computer Networks: Introduction to CN Data Communication DLL: Access Control DLL: Flow Control DLL: Error Control DLL: Framing Data Link Layer - Ethernet Net Layer: IPv4 & Proto Net Layer: IP Addressing Net Layer:Routing Protocol Transport Layer Services TL: Congestion & UDP Application Layer
  15. Unit 8 | Software Engineering: Fundamentals of Software Engineering Software Requirements and Quality Assurance Software Design, Estimation and Metrics Software Testing Software Maintenance and Configuration Management
  16. Unit 9 | Object Oriented Programming: OOPS with C++
  17. Unit 10 | Web Development: HTML Basics CSS JavaScript-Basics XML Node.js Git & Github PHP
  18. Unit 11 | Theory Of Computation: Introduction to TOC Deterministic FA (DFA) Non-Deterministic FA Regular Expressions Grammar Regular Language Properties Moore & Mealy Machines Pushdown Automata & CFG Turing Machines
  19. Unit 12 | IoT: Cloud Computing Internet of Things Network Access Technologies
  20. Unit 13 | Artificial Intelligence: Approaches to AI Search Algorithms Game Playing Knowledge Representation Natural Language Processing Artificial Neural Networks Genetic Algorithms Emerging Trends and AI
  21. Unit 14 | E-Commerce: Volume - I Volume - II Electronic Data Interchange and E-Commerce Role of Internet and Web Services Security in Mobile and Wireless Computing Physical Security and Cryptography Basics Cyber Safety and Security
  22. Unit 15 | Multimedia: Multimedia
  23. Unit 16 | Python: Introduction to Python Tokens, Variables, Data Types, I/O Operators & Expressions Control Flow & Looping Collections & Strings Functions & Modules File Handling & Data Analysis DSA using Python
  24. Full Length Mock Tests — General Paper:
  25. Full Length Mock Tests — Computer Science (Paper II):
  26. Full Length Mock Test – General + Computer Science:
AI summary & chapters

AI Summary

An AI-generated summary of this video lecture.

This lecture, titled "4. Routing Requests and User Input," teaches how to build a basic Node.js HTTP server that routes requests based on the URL and handles user input via HTML forms. The instructor begins by creating a server with `http.createServer` and inspecting incoming request data using `req.url`, `req.method`, and `req.headers`. The core of the lesson focuses on implementing routing logic with conditional statements: an `if` block checks for the root path (`req.url === '/'`) to serve a "Welcome to Home page" response, an `else if` block checks for `/products` (using `.toLowerCase()` in some examples) to serve a products page, and a final `else` block returns a 404 Not Found status with an appropriate HTML page. The instructor emphasizes setting the `Content-Type` header to `text/html` and terminating responses with `res.end()`. The second half of the lecture transitions to "4.6 Taking User Input," where the instructor builds an HTML form using `res.write` calls to output text inputs (for username and email) and radio buttons for gender selection. The form is configured with `action="/submit-details"` and `method="POST"`. The instructor demonstrates the form rendering in a browser, opens DevTools to inspect network requests, and then implements server-side logic to handle the POST submission by routing the request and displaying the submitted data dynamically in a new HTML response. The lesson concludes with the browser showing the result page after form submission, reinforcing how user input flows from the client to the server and back.

Chapters

  1. 0:00 – 2:00 00:00-02:00

    The instructor introduces request routing in a Node.js HTTP server by examining the `req.url` property. On-screen code shows `http.createServer((req, res) => { ... })` with an `if (req.url === '/')` condition that writes `<h1>Welcome to Home page</h1>` and an `else if (req.url.toLowerCase() === '/products')` condition that writes `<h1>Products</h1>`. The instructor also demonstrates logging request details with `console.log(req.url, req.method, req.headers)` and setting the response header via `res.setHeader('Content-Type', 'text/html')`. The browser output transitions from an external e-commerce reference site to a locally served page displaying "Like / Share / Subscribe" as an `<h1>` tag, confirming the server is running and responding correctly.

  2. 2:00 – 5:00 02:00-05:00

    The instructor expands the routing logic by adding a 404 handler. The code progresses from a basic callback that logs the request and writes an HTML response for any route to one with explicit conditional branches. An `if (req.url === '/')` block handles the root path, an `else if (req.url === '/products')` block handles the products endpoint, and a final `else` block sets `res.statusCode = 404` and writes an HTML page with `<title>404 Page Not Found</title>`. The instructor reinforces the pattern of using `res.write` to construct HTML and calling `res.end()` after each route's response is complete. The on-screen code consistently shows the structure of branching on `req.url` to determine which HTML content to send back to the client.

  3. 5:00 – 10:00 05:00-10:00

    The instructor reviews the complete routing implementation, with editor tooltips displaying `server.listen(handle[, backlog][, callback])` and parameter types `res: http.ServerResponse` and `req: http.IncomingMessage`. The routing code branches on `if (req.url === '/')` and `else if (req.url === '/products')`, each writing different HTML via `res.write`. A closing slide titled "4.5 Routing Requests" highlights each `return res.end();` line with a red box and green checkmark, emphasizing that every route must terminate the response. The terminal shows "Node.js v22.5.1" and the editor tab reads "NodeJS_Complete_YouTube," confirming the runtime environment. This section consolidates the routing pattern before transitioning to user input handling.

  4. 10:00 – 15:00 10:00-15:00

    The lecture shifts to "4.6 Taking User Input," with a slide showing code that writes a form with `action="/submit-details"`, `method="POST"`, and male/female radio inputs. The instructor switches to a file named `user.js` and writes an `<h1>` tag reading "Enter Your Details" inside a form block. Line 12 adds `res.write('<input type="text" name="username" placeholder="Enter your name">')` with the word `name` highlighted, demonstrating how form field names map to server-side data. The browser tab shows "Welcome to Home" with the DevTools Network panel open, allowing students to inspect the request/response cycle. The instructor continues adding form fields including email input and radio buttons for gender selection, building the complete input interface.

  5. 15:00 – 20:00 15:00-20:00

    The instructor completes the form by adding a submit button with `res.write('<button type="submit">Submit</button>')` and demonstrates the rendered "Enter Your Details" page in the browser, showing a text field and Male/Female radio options. The code includes `res.write('<input type="radio" id="male" name="gender" value="male">')` and `res.write('<input type="text" id="name" name="name" placeholder="Enter your name"><br><br>')`. The instructor then implements server-side handling for the form submission by routing the POST request to `/submit-details` and writing out an `<h1>` tag with the submitted data. The browser displays the result page titled "Like / Share / Subscribe" after form submission, demonstrating how user input flows from the client form to the server and back as a dynamic response.

  6. 20:00 – 21:14 20:00-21:14

    The final segment reinforces the complete user input workflow. The instructor reviews the form code with `action="/submit-details" method="POST"` and the radio input `<input type="radio" id="male" name="gender" value="male">`. The browser shows the rendered form and the result page after submission, with `res.setHeader('Content-Type', 'text/html')` ensuring proper rendering. The on-screen text includes "4.6 Taking User Input," "Enter Your Details:", and the website watermark "www.completecoding.in." This closing section ties together routing and user input, showing how a Node.js server can accept form data via POST requests and respond with dynamically generated HTML based on the submitted values.

The lecture follows a clear pedagogical progression from routing to user input. First, the instructor establishes that `req.url` is the primary mechanism for determining which route a request targets. The routing pattern uses sequential `if/else if/else` blocks inside the `http.createServer` callback, with each branch writing specific HTML content and terminating with `res.end()`. The 404 handler in the final `else` block ensures unmatched URLs receive an appropriate error response. Key technical details include setting `Content-Type: text/html` before writing HTML, using `.toLowerCase()` for case-insensitive URL matching in some examples, and the importance of calling `res.end()` to complete each response. The transition to user input introduces HTML forms as the mechanism for collecting client data. The form uses `action="/submit-details"` and `method="POST"` to direct submissions to a specific server route. Form fields are defined with `name` attributes that become accessible on the server side, and different input types (text, email, radio) demonstrate varied data collection patterns. The DevTools Network panel is used to inspect the request/response cycle, helping students visualize how form data travels from browser to server. The final demonstration shows the complete round-trip: user fills the form, submits via POST, server processes the request at `/submit-details`, and responds with dynamically generated HTML displaying the submitted data. This end-to-end example reinforces how routing and user input work together in a Node.js HTTP server.

Loading lesson…