6

I'm currently switching from restified to Express, and I noticed that the output of res.send({}) in Express has pretty-printed JSON with white space, while the Restify output is minified without white space.

Since the JSON is not for human consumption, I prefer the minified output. Is there an easy way to get Express to output minified JSON without individually changing all the res.send() calls? I would also prefer a setting over adding more middle-ware for performance reasons.

Killroy
  • 906
  • 1
  • 13
  • 24

1 Answers1

21

You can set the json spaces setting to 0:

var app = express();

app.set('json spaces', 0);

Express will do that automatically when you run it in production mode, though:

NODE_ENV=production node app
robertklep
  • 198,204
  • 35
  • 394
  • 381
  • 1
    See here for instructions for windows: http://stackoverflow.com/questions/9249830/how-can-i-set-node-env-production-in-windows – Killroy Nov 07 '13 at 13:40
  • 1
    @Killroy oh yeah sorry, so used to Unix/Mac that I forgot about Windows :) – robertklep Nov 07 '13 at 13:43