Express.js res.jsonp() Function
Last Updated :
16 Mar, 2023
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 response.
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) {
res.jsonp({ title: 'GeeksforGeeks' });
});
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:
Now open the browser and go to http://localhost:3000/, now on your screen you will see the following output:
{"title":"GeeksforGeeks"}
Example 2: Filename: index.js
JavaScript
const express = require('express');
const app = express();
const PORT = 3000;
// With middleware
app.use('/', function (req, res, next) {
res.jsonp({ name: 'Legend' });
next();
})
app.get('/', function (req, res) {
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 browser screen and you will see the following output:
{"name":"Legend"}
Reference: https://expressjs.com/en/5x/api.html#res.jsonp
Similar Reads
Express res.end() Function The res.end() function concludes the response process and is derived from the HTTP.ServerResponse's response.end() method in the Node core. It is employed to promptly conclude the response without including any data.Syntax: res.end([data] [, encoding])Parameters: The default encoding is 'utf8' and t
2 min read
Express res.status() Function The res.status() function sets the HTTP status for the response. It is a chainable alias of Nodeâs response.statusCode. Syntax:res.status( code )Parameter: This function accepts a single parameter code that holds the HTTP status code. Return Value: It returns an Object. Steps to create the Express A
2 min read
Express app.use() Function The app.use() function in Express.js adds middleware to the application's request-processing pipeline. It applies the specified middleware to all incoming requests or to specific routes, allowing you to modify request/response objects, perform operations, or handle errors throughout the application.
3 min read
Express res.cookie() Function The res.cookie() function is used to set a cookie in the client's browser. It allows you to assign a cookie by providing a name and a value. The value can be a simple string or an object, which will be automatically converted to JSON.Syntax:res.cookie(name, value [, options])name: The name of the co
2 min read
ExpressJS express.json() Function The express.json() function is a built-in middleware in Express that is used for parsing incoming requests with JSON payload. The express.json middleware is important for parsing incoming JSON payloads and making that data available in the req.body or further processing within the routes. Without us
4 min read
Express app.post() Function The app.post() function in Express.js handles HTTP POST requests to a specific route. It defines a callback function to process incoming data sent via POST, typically used for submitting forms or sending data to a server from clients.Syntax:app.post(path, callback [, callback ...])Arguments:Path: Th
2 min read