Posted on: August 17th, 2011 by

This isn’t rocket science, but thought I’d post it since I had trouble finding an example of it…

This demonstrates how to utilize the JSONP support in the Express node.js module.

var express = require("express");

var server = express.createServer();
server.enable("jsonp callback");
server.get("/foo", function(req, res) {
    // this is important - 
    // you must use Response.json()

An HTTP GET request to /foo?callback=myfunction would return myfunction("hello");, with the Content-Type header set to text/javascript.

Total Comments(2)

  1. Clint says:

    Thanks for this. Like you said, it’s small, but I just needed to see an example.

  2. Robert says:

    Thanks! – Just what I was looking for and I hadn’t found it in the docs.