Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • NodeJS Tutorial
  • NodeJS Exercises
  • NodeJS Assert
  • NodeJS Buffer
  • NodeJS Console
  • NodeJS Crypto
  • NodeJS DNS
  • NodeJS File System
  • NodeJS Globals
  • NodeJS HTTP
  • NodeJS HTTP2
  • NodeJS OS
  • NodeJS Path
  • NodeJS Process
  • NodeJS Query String
  • NodeJS Stream
  • NodeJS String Decoder
  • NodeJS Timers
  • NodeJS URL
  • NodeJS Interview Questions
  • NodeJS Questions
  • Web Technology
Open In App
Next Article:
Express.js res.set() Function
Next article icon

Express.js res.get() Function

Last Updated : 16 Mar, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

The res.get() function returns the HTTP response header specified by the field. The match is case-insensitive.

Syntax: 

res.get( field )

Parameter: The field parameter describes the name of the field.

Return Value: It returns an Object.

Installation of the express module: 

You can visit the link to Install the express module. You can install this package by using this command. 

npm install express

After installing the express module, you can check your express version in the command prompt using the command. 

npm version express

After that, you can just create a folder and add a file, for example, index.js. To run this file you need to run the following command. 

node index.js

Project Structure:

Example 1: Filename: index.js 

javascript

const express = require('express');
const app = express();
const PORT = 3000;
 
// Without middleware
app.get('/', function (req, res) {
 
    // Setting the response
    res.set({
        'Content-Type': 'text/plain',
        'Content-Length': '123',
        ETag: '12345'
    });
 
    // "text/plain"
    console.log(res.get('Content-Type'));
});
 
app.listen(PORT, function (err) {
    if (err) console.log(err);
    console.log("Server listening on PORT", PORT);
});
                      
                       

Steps to run the program: 

Make sure you have installed the express module using the following command: 

npm install express

Run the index.js file using the below command: 

node index.js

Output:

Console Output:

Server listening on PORT 3000

Browser Output:

Open your browser and go to http://localhost:3000/ and then you will see the following output on your console: 

Server listening on PORT 3000 text/plain; charset=utf-8

Example 2: Filename: index.js 

javascript

const express = require('express');
const app = express();
const PORT = 3000;
 
// With middleware
app.use('/', function (req, res, next) {
    //Setting the response
    res.set({
        'Content-Type': 'text/html',
        'Content-Length': '33',
        ETag: '66'
    });
    next();
})
 
app.get('/', function (req, res) {
    console.log(res.get('Content-Type'));
    res.send();
});
 
app.listen(PORT, function (err) {
    if (err) console.log(err);
    console.log("Server listening on PORT", PORT);
});
                      
                       

Steps to run the program:

Run the index.js file using the below command:  

node index.js

Output:

Now open the browser and go to http://localhost:3000/, now check your console and you will see the following output:  

text/html; charset=utf-8

Reference: https://expressjs.com/en/5x/api.html#res.get



Next Article
Express.js res.set() Function
author
gouravhammad
Improve
Article Tags :
  • Express.js
  • Node.js
  • Web Technologies

Similar Reads

  • Express.js req.get() Function
    The req.get() function returns the specified HTTP request header field which is a case-insensitive match and the Referrer and Referrer fields are interchangeable. Syntax: req.get( field )Parameter: The field parameter specifies the HTTP request header field. Return Value: String. Installation of the
    2 min read
  • Express res.json() Function
    The res.json() function sends a JSON response. This method sends a response (with the correct content-type) that is the parameter converted to a JSON string using the JSON.stringify() method. Syntax: res.json( [body] )Parameters: The body parameter is the body that is to be sent in the response. Ret
    2 min read
  • Express.js req.is() Function
    The req.is() function returns the matching content-type if the incoming request’s 'Content-Type' HTTP header field matches with the MIME type that has been specified by the type parameter and it returns null if the request has no body otherwise it returns false. Syntax: req.is( type ) Parameter: The
    2 min read
  • Express.js res.jsonp() Function
    The res.jsonp() function is used to send a JSON response with JSONP support and this function is similar to the res.json() function except that it opts-in to the support of JSONP callback. Syntax:  res.jsonp( [body] ) Parameter: The body parameter describes the body type which can be sent in respons
    2 min read
  • Express.js res.set() Function
    The res.set() function is used to set the response HTTP header field to value. To set multiple fields at once, pass an object as the parameter. Syntax: res.set(field [, value])Parameters: The field parameter is the name of the field and the value parameter is the value assigned to the field paramete
    2 min read
  • Express.js | app.get() Function
    The app.get() function returns the value name app setting. The app.set() function is used to assign the setting name to value. This function is used to get the values that are assigned.  Syntax: app.get(name) Installation of the express module: You can visit the link to Install the express module. Y
    1 min read
  • Express.js res.vary() Function
    The res.vary() function is used to add the field to the Vary response header, if it is not there already. The Vary header indicates which headers it’s basically used for content negotiation. Syntax:  res.vary( field ) Parameter: The field parameter describes the name of the field. Return Value: It r
    2 min read
  • Express.js res.type() Function
    The res.type() function is used to set the Content-Type HTTP header to the MIME type determined by the mime.lookup() function for the specified type.  Syntax:  res.type( type ) Parameters: The type parameter describes the MIME type. Return Value: It returns an Object. Installation of the express mod
    2 min read
  • Express.js res.links() Function
    The res.links() function is used to join the links provided as properties of the parameter to populate the response’s Link HTTP header field. Syntax:  res.links( links ) Parameter: The link parameter describes the name of the link to be joined. Return Value: It returns an Object. Installation of the
    2 min read
  • Express app.get() Request Function
    The app.get() function is used to define routes on your server that handle HTTP GET requests. A GET request is typically used when the client asks the server to send back some information, like retrieving a webpage or data from a database. It’s an essential part of building websites and APIs, as it
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences