Not A Subscriber?
Join thousands of people who build and refuse to get left behind. One message a week on building, using AI as an accelerator, and staying sharp in the new AI frontier.
Receive one free message a weekJune 27, 2012 Donn Felker · updated July 5, 2013
Node.js with Express 3 res.json Changes
Node v0.8.0 was released this week. Being a good software developer (nah, lets be honest … maybe just a little bit insane one) I decided to update my sample application I’m using for an upcoming article and conference sessions on building API’s with Node.js and the Express web framework. My current application was using Node v0.6.19 and Express 2.5.10
Upon upgrading I immediately ran into an issue. The res.json(data, status_code) was not working anymore. Instead of returning an array of values I was simply getting the status code back from the app.
The problem was that the order of the params changed.
I posted a question on the Express google group and within a minute TJ already fixed the issue by allowing backwards compatibility of the param order. Very cool. But it is good to note that going forward in Express you will want to use res.json(status_code, data). Kudos to the quick turn around TJ!