Can Express.Js output minified JSON?
Asked Answered
U

1

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.

Usury answered 7/11, 2013 at 10:12 Comment(0)
F
22

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
Factorize answered 7/11, 2013 at 10:29 Comment(2)
See here for instructions for windows: #9250330Usury
@Usury oh yeah sorry, so used to Unix/Mac that I forgot about Windows :)Factorize

© 2022 - 2024 — McMap. All rights reserved.