Created
June 27, 2012 21:20
-
-
Save donnfelker/3006934 to your computer and use it in GitHub Desktop.
Express 3 Changes in res.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// v0.6.19 way of returning JSON. | |
exports.index = function(req, res) { | |
Workout.find({}, function(err, docs) { | |
if(!err) { | |
res.json( { workouts: docs }, 200); | |
} else { | |
res.json( { message: err }, 500); | |
} | |
}); | |
} | |
// v0.8.0 way of returning JSON, note the change of order of params | |
exports.index = function(req, res) { | |
Workout.find({}, function(err, docs) { | |
if(!err) { | |
res.json(200, { workouts: docs }); | |
} else { | |
res.json(500, { message: err }); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment