Open In App

Express app.get() Request Function

Improve
Improve
Like Article
Like
Save
Share
Report

The `app.get()` function in Node is designed to route HTTP GET requests to the specified path, associating them with designated callback functions. Its primary purpose is to link middleware to your application, facilitating the handling of GET requests at the specified route.

Syntax:

app.get( path, callback )

Parameters:

  • path: It is the path for which the middleware function is being called. 
  • callback: They can be a middleware function or a series/array of middleware functions. 

Steps to create the application:

Step 1: You can install this package by using this command.

npm install express

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

npm version express

Project Structure:

NodeProj

The updated dependencies in package.json file will look like:

"dependencies": {
"express": "^4.18.2",
}

Example 1: Below is the code example of app.get() Function:

javascript




const express = require('express');
const app = express();
const PORT = 3000;
 
app.get('/', (req, res) => {
    res.send("GET Request Called")
})
 
app.listen(PORT, function (err) {
    if (err) console.log(err);
    console.log("Server listening on PORT", PORT);
});


Steps to run the program: 

node index.js

Console Output:  

Server listening on PORT 3000

Browser Output: Now make a GET request to http://localhost:3000/ and you will get the following

14nodeget

Output

We have a complete list of all the important Express Application methods, to check those please go through Express.js Application Complete Reference article


Last Updated : 18 Jan, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads