You can compress any kind of binary data (strings, Buffers) with Node.js, no external deps required, using the zlib module.
You can use either gzip or deflate compression algorithms, depending on your needs.
Example
(shamelessly stolen from Node.js' website)
const zlib = require('zlib')
const input = JSON.stringify({ some: 'json-data' })
zlib.deflate(input, (err, buffer) => {
if (err) {
console.log('u-oh')
}
// Send buffer as string to client using my imaginary io object
io.send(buffer.toString('base64'))
})
Update: It might be better to just enable HTTP compression on the transport layer instead of compressing and decompressing the data on your own.