res.jsonp()
Send a JSON or JSONP response.
Identical to res.json()
, except if a "callback" parameter exists, a JSONP response will be sent instead, using the value of the "callback" parameter as the name of the function wrapper.
Usage
return res.jsonp([statusCode, ] data);
Example
return res.jsonp({
users: [{
name: 'Thelma',
id: 1
}, {
name: 'Leonardo'
id: 2
}]
});
Notes
- Don't forget this method's name is all lowercase.
- This method is terminal, meaning it is generally the last line of code your app should run for a given request (hence the advisory usage of
return
throughout these docs).