Node.js http.ClientRequest.getHeader() API Last Updated : 08 Jul, 2021 Comments Improve Suggest changes Like Article Like Report The http.ClientRequest.getHeader() is an inbuilt application programming interface of class ClientRequest within http module which is used to get the header object of the particular header name. Syntax: const request.getHeader(name) Parameters: This method takes the name of the header as a parameter. Return Value : This method returns the object of the header as output. Example 1: JavaScript // Node.js program to demonstrate the // request.getHeader() APi // Importing http module const http = require('http'); // Create an HTTP server http.createServer((req, res) => {}).listen(3000, '127.0.0.1', () => { // getting client request const req = http.request({ port: 3000, host: '127.0.0.1', }); req.setHeader('content-type', 'text/html'); // getting header // by using getHeader() api console.log("header :- " + req.getHeader('content-type')) process.exit(0) }); Output: Example 2: JavaScript // Node.js program to demonstrate the // request.getHeader() APi // Importing http module const http = require('http'); // Create an HTTP server const server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('okay'); }); // Now that server is running server.listen(3000, '127.0.0.1', () => { // make a request const options = { port: 3000, host: '127.0.0.1', headers: { 'Connection': 'Upgrade', 'Upgrade': 'websocket' } }; // getting client request const req = http.request(options); req.setHeader('Cookie', ['type=ninja', 'language=javascript']); // getting header // by using getHeader() api const v = req.getHeader('Cookie'); // display the result console.log("header :- " + v) process.exit(0) }); Output: Reference: https://nodejs.org/dist/latest-v12.x/docs/api/http.html#http_request_getheader_name Comment More infoAdvertise with us Next Article Must Coding Questions - Company-wise R rohitprasad3 Follow Improve Article Tags : Web Technologies Node.js NodeJS-API Similar Reads Interview PreparationInterview Preparation For Software DevelopersMust Coding Questions - Company-wise Must Do Coding Questions - Topic-wiseCompany-wise Practice ProblemsCompany PreparationCompetitive ProgrammingSoftware Design-PatternsCompany-wise Interview ExperienceExperienced - Interview ExperiencesInternship - Interview ExperiencesPractice @GeeksforgeeksProblem of the DayTopic-wise PracticeDifficulty Level - SchoolDifficulty Level - BasicDifficulty Level - EasyDifficulty Level - MediumDifficulty Level - HardLeaderboard !!Explore More...Data StructuresArraysLinked ListStackQueueBinary TreeBinary Search TreeHeapHashingGraphAdvance Data StructuresMatrixStringAll Data StructuresAlgorithmsAnalysis of AlgorithmsSearching AlgorithmsSorting AlgorithmsPattern SearchingGeometric AlgorithmsMathematical AlgorithmsRandomized AlgorithmsGreedy AlgorithmsDynamic ProgrammingDivide & ConquerBacktrackingBranch & BoundAll AlgorithmsProgramming LanguagesCC++JavaPythonC#Go LangSQLPHPScalaPerlKotlinWeb TechnologiesHTMLCSSJavaScriptBootstrapTailwind CSSAngularJSReactJSjQueryNodeJSPHPWeb DesignWeb BrowserFile FormatsComputer Science SubjectsOperating SystemsDBMSComputer NetworkComputer Organization & ArchitectureTOCCompiler DesignDigital Elec. & Logic DesignSoftware EngineeringEngineering MathematicsData Science & MLComplete Data Science CourseData Science TutorialMachine Learning TutorialDeep Learning TutorialNLP TutorialMachine Learning ProjectsData Analysis TutorialTutorial LibraryPython TutorialDjango TutorialPandas TutorialKivy TutorialTkinter TutorialOpenCV TutorialSelenium TutorialGATE CSGATE CS NotesGate CornerPrevious Year GATE PapersLast Minute Notes (LMNs)Important Topic For GATE CSGATE CoursePrevious Year Paper: CS exams Like