The app.get() function routes the HTTP GET Requests to the path which is being specified with the specified callback functions. Basically is it intended for binding the middleware to your application.
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 series/arrray of middleware functions.
Installation of express module:
- You can visit the link to Install express module. You can install this package by using this command.
npm install express
- After installing express module, you can check your express version in 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
Filename: index.js
var express = require('express'); var app = express(); var 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); }); |
chevron_right
filter_none
Steps to run the program:
- The project structure will look like this:

- Make sure you have installed express module using following command:
npm install express
- Run index.js file using below command:
node index.js
Output:
Server listening on PORT 3000
-
Now make GET request to http://localhost:3000/ and you will get the following output:
GET Request Called
Recommended Posts:
- HTTP Request vs HapiJS Request in Node.js
- Scaffolding an ExpressJS app from scratch
- Routing Path for ExpressJS
- HandleBars Templating in ExpressJS
- Node.js | https.request() Function
- How to send a GET request from PHP?
- HTTP headers | Access-Control-Request-Headers
- Node.js | Request Module
- How to make JavaScript wait for a API request to return?
- HTTP headers | Access-Control-Request-Method
- Simple POST request using the fetch API
- DELETE request using XMLHttpRequest by making Custom HTTP library
- Difference between PUT and DELETE request in Vanilla JavaScript
- Get request using AJAX by making Custom HTTP library
- POST request using AJAX by making Custom HTTP library
- How to make PUT request using XMLHttpRequest by making Custom HTTP library ?
- Simple GET and POST request using Fetch API method by making custom HTTP library
- Difference between GET and POST request in Vanilla JavaScript
- How to make simple PUT request using fetch API by making custom HTTP library ?
- Simple DELETE request using fetch API by making custom HTTP library
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

