JSON formatting in iisnode
Problem
When running my node.js application locally, I get nicely formatted JSON output with line breaks and spaces, like this:
{
"foo": "bar",
"asdf": "qwerty"
}
But when I run the same code in iisnode on Azure, I get this:
{"foo":"bar","asdf":"qwerty"}
Not that it makes any functional difference, and the latter one even saves some extra bytes, but it would be nice to know where the difference comes from.
Here is the code:
exports.test = function(req, res){
var result = { foo : 'bar', asdf : 'qwerty'};
res.send(result);
}
Problem courtesy of: hsg
Solution
The difference is likely with the NODE_ENV
environment variable and express
' default configurations:
app.defaultConfiguration = function(){
// ...
this.configure('development', function(){
this.set('json spaces', 2);
});
// ...
};
Azure must have a different value for NODE_ENV
(probably 'production'
) so the configure()
callback gets skipped.
Solution courtesy of: Jonathan Lonowski
Discussion
View additional discussion.