Compressing object-body content from a Node.js server built using the express module

If space is your primary concern when using JSON that has you considering a binary representation, you should seriously consider using compression instead. Compression can yield similar savings to a binary representation, it is implemented with gzip in most servers and HTTP clients, and can be added as a transparent layer after you've finished debugging your application. Here, we discuss adding object-body compression for JSON and other objects sent by the popular express server built on top of Node.js with the express module.

Getting ready

First, you need to make sure you've installed the express and compress modules:

npm install express
npm install compression ...

Get JavaScript JSON Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.