In Express.js, res.jsonp() sends a JSON response with JSONP support. Official docs: it is identical to res.json(), except it opts in to wrapping the payload in a JavaScript callback when the client passes a callback query parameter.
By default the query key is callback (?callback=foo → foo({…})). Override with app.set('jsonp callback name', 'cb'). For new APIs, prefer res.json() plus CORS instead of JSONP.
Syntax
Call res.jsonp in your Express.js app. Start with this line.
GET /api/legacy-user?callback=foo
→ foo({"id":1,"name":"Mari"});
GET /api/legacy-user
→ {"id":1,"name":"Mari"}
(no wrapper when callback query is absent)
How It Works
Same payload as json. You pass a normal object.
Callback query opts in. Default key is callback.
Body becomes a call.?callback=foo → foo({…}) per the docs.
Legacy script tags can load that URL and run the function.
Example 2 — Customize the Callback Query Key
Use app.set('jsonp callback name', 'cb') when clients send ?cb=.
GET /api/legacy-orders/abc?callback=foo
→ 400
→ foo({"error":"Invalid id"});
GET /api/legacy-orders/7?callback=foo
→ 200
→ foo({"id":7,"status":"queued"});
How It Works
status then jsonp. Same chaining style as res.status().json().
return on errors so you do not send twice.
Callback still wraps the error object when the query is present.
HTTP status remains meaningful for XHR clients; script-tag clients mainly execute the function body.
Compatibility
Runtime Support
res.jsonp() is an Express.js response method. It runs on a Node.js server (Express 5 needs Node.js 18+). Clients receive either JSON or a callback-wrapped script body.
✓ Server · Express 4 & 5
res.jsonp()
Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers. Not a browser API.
ServerNode.js runtime API
Node.js18+ for Express 5 · Express 4 supported
Supported
BunExpress-compatible server apps
Supported
DenoVia npm compatibility / adapters
Supported
res.jsonp()Express on Node.js
Bottom line: Study with Node.js and express. For new APIs, prefer res.json() and CORS; use jsonp only for legacy needs.
Frequently Asked Questions
It is identical to res.json(), except it opts in to JSONP callback support. When a callback query param is present, the JSON is wrapped like callback({ ... }).
callback. So ?callback=foo wraps the payload as foo(...). Change it with app.set('jsonp callback name', 'cb').
Mainly for legacy clients that load data via a script tag. Modern APIs should use res.json() with CORS instead.
Yes. Example from the docs: res.status(500).jsonp({ error: 'message' }).
No — the method is still available. It is a legacy cross-domain pattern; prefer CORS + JSON for new work.