Node Js Server with compression
const express = require('express');
const compression = require('compression');
const app = express();
app.use(compression());
app.get("/compress", (req, res) => {
const text = `Lorem Ipsum is simply dummy text of the ...`;
res.json({text: text.repeat(10)});
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
It is showing the same size before and after compression on google chome.
I am not sure if I need a compression module or not.

I ran your code and tested few things and here are my findings.
- With compression, your response is 701 bytes. Every consequent once is 179 byte. This is due to browser caching, with or without compression after initial load, cache is created and for some time, only that cache is used.
- This is where it got interesting, without compression response size was 678 bytes, so compression actually added more size. This is due to extra header that compression adds. It needs extra header to let browser know that this data was compressed and browser needs to decompress it. If you look into response headers for both cases, for compression enabled this is extra header of
Vary: Accept-Encoding. My guess is, due to the fact that data is already small, compression library decided not to use any compression algorithm, or algorithm itself decided not to change anything, since in some cases extra compression overhead is not worth it.
- To confirm my guess, I ran other test, where I used text.repeat(100) and this is where I saw true results. With compression data size was 407 bytes and without it was 4.5 kbs, so compression worked and it made huge difference(around 10x smaller). Also after initial load, again browser caching was applied and both sizes of compressed and non compressed responses were 180 bytes.
In conclusion, applying compression is mostly useful and good idea. Effects may not be visible with small response data size, but larger it is, more significant difference will be(it depends on many stuff like which compression algorithm you use and what type of data you have, library actually allows you to configure some of the stuff). Also in cases of browser, after initial load caching is applied and size will be similar no matter if it's compressed or not.