← All articles
development

Node.js with Express 3 res.json Changes

Upgrading to Node 0.8 and Express 3 broke res.json(data, status), the param order flipped to res.json(status, data). Here's the fix.

Donn Felker

Donn Felker

2012.06.27 · 1 min read · updated July 5, 2013

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!

Donn Felker

Written by Donn Felker

I've spent 25+ years shipping software, writing books, and running my own companies. I write about thinking clearly, working for yourself, and doing real work while AI rewrites the rules. New essays land here every week.

Get the newsletter

Keep reading