I built the same API with & without Express. Here are the differences.
By: Yrjguygjytjg Yoyitbifbitjf Figgjgitgigfuykhfu
Tags: Nodejs, JavaScript, Web Development, Expressjs, Programming

Source: The author

Express.js is now the standard in the Node.js world. If backend wants to develop applications for the web, the npm install express is pre-programmed and has become routine for most of us.

Admittedly, working with Express.js is much more pleasant — when I learned Node.js, I went straight into Express. Before this experiment, I probably never wrote anything without Express.js.

That’s why I had a great desire to put Express to the test — and test it in the form of a small API with a native approach.

So I built the same API twice, once with and once without Express. You can see the code below — first a little tip.

When I gave both APIs a test run, I noticed the following: The response of the Express app is about 15% higher.

This is of course problematic if you want to make a fair benchmark that measures the performance of the server.

The different size is not due to the content of our response, because we send the same from both servers with res.end() , but to the headers.

Express.js comes with something in the header by default, which is only meant cosmetically — the X-Powered-By tag.

X-Powered-By Express.js Tag

But we can simply deactivate it: app.disable('x-powered-by')

Then the two responses of the different servers should be exactly the same size. Let’s have a look at the code.

The Express.js API:

The API without Express.js:

Logically, both APIs do absolutely the same thing. They only respond to the /api-route and return the query parameters they receive.

http://landrover.gi/land/atp/sub-Thiem-v-Tsitsipas-cbn-00.html

http://landrover.gi/land/atp/sub-Thiem-v-Tsitsipas-cbn-01.html

http://landrover.gi/land/atp/sub-Thiem-v-Tsitsipas-cbn-02.html

http://landrover.gi/land/atp/sub-Thiem-v-Tsitsipas-cbn-03.html

https://sv.tie.org/sv/atp/sub-Thiem-v-Tsitsipas-cbn-00.html

https://sv.tie.org/sv/atp/sub-Thiem-v-Tsitsipas-cbn-01.html

https://sv.tie.org/sv/atp/sub-Thiem-v-Tsitsipas-cbn-02.html

https://sv.tie.org/sv/atp/sub-Thiem-v-Tsitsipas-cbn-03.html

https://sv.tie.org/sv/socc/dr--Video-Slovakia-vs-Scotland-news-90.html

https://sv.tie.org/sv/socc/dr--Video-Slovakia-vs-Scotland-news-91.html

https://sv.tie.org/sv/socc/dr--Video-Slovakia-vs-Scotland-news-92.html

https://sv.tie.org/sv/socc/dr--Video-Slovakia-vs-Scotland-news-93.html

https://altagamma.it/dia/Video-burundi-mauritania-en-direct5-v-fr-fr-1bgb.html

https://altagamma.it/dia/Video-burundi-mauritania-en-direct5-v-fr-fr-1bgb1.html

https://altagamma.it/dia/Video-burundi-mauritania-en-direct5-v-fr-fr-1bgb2.html

https://altagamma.it/dia/Video-burundi-mauritania-en-direct5-v-fr-fr-1bgb3.html

http://landrover.gi/land/socc/dr--Video-Slovakia-vs-Scotland-news-90.html

http://landrover.gi/land/socc/dr--Video-Slovakia-vs-Scotland-news-91.html

http://landrover.gi/land/socc/dr--Video-Slovakia-vs-Scotland-news-92.html

http://landrover.gi/land/socc/dr--Video-Slovakia-vs-Scotland-news-93.html

https://oasislandscape.com/cap/atp/sub-Thiem-v-Tsitsipas-cbn-00.html

https://oasislandscape.com/cap/atp/sub-Thiem-v-Tsitsipas-cbn-01.html

https://oasislandscape.com/cap/atp/sub-Thiem-v-Tsitsipas-cbn-02.html

https://oasislandscape.com/cap/atp/sub-Thiem-v-Tsitsipas-cbn-03.html

https://www.oasislandscape.com/cap/socc/dr--Video-Slovakia-vs-Scotland-news-90.html

https://www.oasislandscape.com/cap/socc/dr--Video-Slovakia-vs-Scotland-news-91.html

https://www.oasislandscape.com/cap/socc/dr--Video-Slovakia-vs-Scotland-news-92.html

https://www.oasislandscape.com/cap/socc/dr--Video-Slovakia-vs-Scotland-news-93.html

https://www.oasislandscape.com/cap/gp/rex-r-v-m0.html

https://www.oasislandscape.com/cap/gp/rex-r-v-m1.html

https://www.oasislandscape.com/cap/gp/rex-r-v-m2.html

https://www.oasislandscape.com/cap/gp/rex-r-v-m3.html

https://www.oasislandscape.com/cap/gp/rex-r-v-m4.html

http://landrover.gi/land/gp/rex-r-v-m0.html

http://landrover.gi/land/gp/rex-r-v-m1.html

http://landrover.gi/land/gp/rex-r-v-m2.html

http://landrover.gi/land/gp/rex-r-v-m3.html

http://landrover.gi/land/gp/rex-r-v-m4.html

https://sv.tie.org/sv/gp/rex-r-v-m0.html

https://sv.tie.org/sv/gp/rex-r-v-m1.html

https://sv.tie.org/sv/gp/rex-r-v-m2.html

https://sv.tie.org/sv/gp/rex-r-v-m3.html

https://sv.tie.org/sv/gp/rex-r-v-m4.html

https://www.oasislandscape.com/cap/gp/E-M-v-V-es02.html

https://www.oasislandscape.com/cap/gp/E-M-v-V-es03.html

https://www.oasislandscape.com/cap/gp/E-M-v-V-es04.html

https://www.oasislandscape.com/cap/gp/E-M-v-V-es05.html

https://www.oasislandscape.com/cap/gp/E-M-v-V-es06.html

http://landrover.gi/land/gp/E-M-v-V-es02.html

http://landrover.gi/land/gp/E-M-v-V-es03.html

http://landrover.gi/land/gp/E-M-v-V-es04.html

http://landrover.gi/land/gp/E-M-v-V-es05.html

http://landrover.gi/land/gp/E-M-v-V-es06.html

https://sv.tie.org/sv/atp/Thiem-v-Tsitsipas-liv-Mara-de000.html

https://sv.tie.org/sv/atp/Thiem-v-Tsitsipas-liv-Mara-de001.html

https://sv.tie.org/sv/atp/Thiem-v-Tsitsipas-liv-Mara-de002.html

https://sv.tie.org/sv/atp/Thiem-v-Tsitsipas-liv-Mara-de003.html

https://sv.tie.org/sv/atp/Thiem-v-Tsitsipas-liv-Mara-de004.html

https://sv.tie.org/sv/atp/Thiem-v-Tsitsipas-liv-Mara-de005.html

https://sv.tie.org/sv/atp/Thiem-v-Tsitsipas-liv-Mara-de006.html

http://landrover.gi/land/atp/Thiem-v-Tsitsipas-liv-Mara-de000.html

http://landrover.gi/land/atp/Thiem-v-Tsitsipas-liv-Mara-de001.html

http://landrover.gi/land/atp/Thiem-v-Tsitsipas-liv-Mara-de002.html

http://landrover.gi/land/atp/Thiem-v-Tsitsipas-liv-Mara-de003.html

http://landrover.gi/land/atp/Thiem-v-Tsitsipas-liv-Mara-de004.html

http://landrover.gi/land/atp/Thiem-v-Tsitsipas-liv-Mara-de005.html

http://landrover.gi/land/atp/Thiem-v-Tsitsipas-liv-Mara-de006.html

https://oasislandscape.com/cap/atp/Thiem-v-Tsitsipas-liv-Mara-de000.html

https://oasislandscape.com/cap/atp/Thiem-v-Tsitsipas-liv-Mara-de001.html

https://oasislandscape.com/cap/atp/Thiem-v-Tsitsipas-liv-Mara-de002.html

https://oasislandscape.com/cap/atp/Thiem-v-Tsitsipas-liv-Mara-de003.html

https://oasislandscape.com/cap/atp/Thiem-v-Tsitsipas-liv-Mara-de004.html

https://oasislandscape.com/cap/atp/Thiem-v-Tsitsipas-liv-Mara-de005.html

https://oasislandscape.com/cap/atp/Thiem-v-Tsitsipas-liv-Mara-de006.html

http://landrover.gi/land/atp/Thiem-Tsitsipas-im-tv-liv-ccf1.html

http://landrover.gi/land/atp/Thiem-Tsitsipas-im-tv-liv-ccf2.html

http://landrover.gi/land/atp/Thiem-Tsitsipas-im-tv-liv-ccf3.html

http://landrover.gi/land/atp/Thiem-Tsitsipas-im-tv-liv-ccf4.html

http://landrover.gi/land/atp/Thiem-Tsitsipas-im-tv-liv-ccf5.html

http://landrover.gi/land/socc/Ss-Slovakia-v-Scotland-liv-hq-tv-UK01.html

http://landrover.gi/land/socc/Ss-Slovakia-v-Scotland-liv-hq-tv-UK02.html

http://landrover.gi/land/socc/Ss-Slovakia-v-Scotland-liv-hq-tv-UK03.html

http://landrover.gi/land/socc/Ss-Slovakia-v-Scotland-liv-hq-tv-UK04.html

http://landrover.gi/land/socc/Ss-Slovakia-v-Scotland-liv-hq-tv-UK05.html

http://landrover.gi/land/socc/Ss-Slovakia-v-Scotland-liv-hq-tv-UK06.html

http://landrover.gi/land/socc/Ss-Slovakia-v-Scotland-liv-hq-tv-UK07.html

http://landrover.gi/land/socc/Ss-Slovakia-v-Scotland-liv-hq-tv-UK08.html

http://landrover.gi/land/socc/Ss-Slovakia-v-Scotland-liv-hq-tv-UK09.html

https://oasislandscape.com/cap/atp/Thiem-Tsitsipas-im-tv-liv-ccf1.html

https://oasislandscape.com/cap/atp/Thiem-Tsitsipas-im-tv-liv-ccf2.html

https://oasislandscape.com/cap/atp/Thiem-Tsitsipas-im-tv-liv-ccf3.html

https://oasislandscape.com/cap/atp/Thiem-Tsitsipas-im-tv-liv-ccf4.html

https://oasislandscape.com/cap/atp/Thiem-Tsitsipas-im-tv-liv-ccf5.html

https://www.oasislandscape.com/cap/socc/Ss-Slovakia-v-Scotland-liv-hq-tv-UK01.html

https://www.oasislandscape.com/cap/socc/Ss-Slovakia-v-Scotland-liv-hq-tv-UK02.html

https://www.oasislandscape.com/cap/socc/Ss-Slovakia-v-Scotland-liv-hq-tv-UK03.html

https://www.oasislandscape.com/cap/socc/Ss-Slovakia-v-Scotland-liv-hq-tv-UK04.html

https://www.oasislandscape.com/cap/socc/Ss-Slovakia-v-Scotland-liv-hq-tv-UK05.html

https://www.oasislandscape.com/cap/socc/Ss-Slovakia-v-Scotland-liv-hq-tv-UK06.html

https://www.oasislandscape.com/cap/socc/Ss-Slovakia-v-Scotland-liv-hq-tv-UK07.html

https://www.oasislandscape.com/cap/socc/Ss-Slovakia-v-Scotland-liv-hq-tv-UK08.html

https://www.oasislandscape.com/cap/socc/Ss-Slovakia-v-Scotland-liv-hq-tv-UK09.html

https://sv.tie.org/sv/atp/Thiem-Tsitsipas-im-tv-liv-ccf1.html

https://sv.tie.org/sv/atp/Thiem-Tsitsipas-im-tv-liv-ccf2.html

https://sv.tie.org/sv/atp/Thiem-Tsitsipas-im-tv-liv-ccf3.html

https://sv.tie.org/sv/atp/Thiem-Tsitsipas-im-tv-liv-ccf4.html

https://sv.tie.org/sv/atp/Thiem-Tsitsipas-im-tv-liv-ccf5.html

https://sv.tie.org/sv/socc/Scot-v-Slov-liv-kamran-virgin00.html

https://sv.tie.org/sv/socc/Scot-v-Slov-liv-kamran-virgin01.html

https://sv.tie.org/sv/socc/Scot-v-Slov-liv-kamran-virgin02.html

https://sv.tie.org/sv/socc/Scot-v-Slov-liv-kamran-virgin03.html

https://sv.tie.org/sv/socc/Scot-v-Slov-liv-kamran-virgin04.html

https://sv.tie.org/sv/socc/Scot-v-Slov-liv-kamran-virgin05.html

https://sv.tie.org/sv/socc/Scot-v-Slov-liv-kamran-virgin06.html

https://sv.tie.org/sv/socc/Scot-v-Slov-liv-kamran-virgin07.html

http://landrover.gi/land/socc/Scot-v-Slov-liv-kamran-virgin00.html

http://landrover.gi/land/socc/Scot-v-Slov-liv-kamran-virgin01.html

http://landrover.gi/land/socc/Scot-v-Slov-liv-kamran-virgin02.html

http://landrover.gi/land/socc/Scot-v-Slov-liv-kamran-virgin03.html

http://landrover.gi/land/socc/Scot-v-Slov-liv-kamran-virgin04.html

http://landrover.gi/land/socc/Scot-v-Slov-liv-kamran-virgin05.html

http://landrover.gi/land/socc/Scot-v-Slov-liv-kamran-virgin06.html

http://landrover.gi/land/socc/Scot-v-Slov-liv-kamran-virgin07.html

https://www.oasislandscape.com/cap/socc/Scot-v-Slov-liv-kamran-virgin00.html

https://www.oasislandscape.com/cap/socc/Scot-v-Slov-liv-kamran-virgin01.html

https://www.oasislandscape.com/cap/socc/Scot-v-Slov-liv-kamran-virgin02.html

https://www.oasislandscape.com/cap/socc/Scot-v-Slov-liv-kamran-virgin03.html

https://www.oasislandscape.com/cap/socc/Scot-v-Slov-liv-kamran-virgin04.html

https://www.oasislandscape.com/cap/socc/Scot-v-Slov-liv-kamran-virgin05.html

https://www.oasislandscape.com/cap/socc/Scot-v-Slov-liv-kamran-virgin06.html

https://www.oasislandscape.com/cap/socc/Scot-v-Slov-liv-kamran-virgin07.html

https://ayf.com/ayf/cll/dr--Video-Slovakia-vs-Scotland-news-90.html

https://ayf.com/ayf/cll/dr--Video-Slovakia-vs-Scotland-news-91.html

https://ayf.com/ayf/cll/dr--Video-Slovakia-vs-Scotland-news-92.html

https://ayf.com/ayf/cll/dr--Video-Slovakia-vs-Scotland-news-93.html

https://ayf.com/ayf/ten/sub-Thiem-v-Tsitsipas-cbn-00.html

https://ayf.com/ayf/ten/sub-Thiem-v-Tsitsipas-cbn-01.html

https://ayf.com/ayf/ten/sub-Thiem-v-Tsitsipas-cbn-02.html

https://ayf.com/ayf/ten/sub-Thiem-v-Tsitsipas-cbn-03.html

https://ayf.com/ayf/cll/Ss-Slovakia-v-Scotland-liv-hq-tv-UK01.html

https://ayf.com/ayf/cll/Ss-Slovakia-v-Scotland-liv-hq-tv-UK02.html

https://ayf.com/ayf/cll/Ss-Slovakia-v-Scotland-liv-hq-tv-UK03.html

https://ayf.com/ayf/cll/Ss-Slovakia-v-Scotland-liv-hq-tv-UK04.html

https://ayf.com/ayf/cll/Ss-Slovakia-v-Scotland-liv-hq-tv-UK05.html

https://ayf.com/ayf/cll/Ss-Slovakia-v-Scotland-liv-hq-tv-UK06.html

https://ayf.com/ayf/cll/Ss-Slovakia-v-Scotland-liv-hq-tv-UK07.html

https://ayf.com/ayf/cll/Ss-Slovakia-v-Scotland-liv-hq-tv-UK08.html

https://ayf.com/ayf/cll/Ss-Slovakia-v-Scotland-liv-hq-tv-UK09.html

https://ayf.com/ayf/ten/Thiem-Tsitsipas-im-tv-liv-ccf1.html

https://ayf.com/ayf/ten/Thiem-Tsitsipas-im-tv-liv-ccf2.html

https://ayf.com/ayf/ten/Thiem-Tsitsipas-im-tv-liv-ccf3.html

https://ayf.com/ayf/ten/Thiem-Tsitsipas-im-tv-liv-ccf4.html

https://ayf.com/ayf/ten/Thiem-Tsitsipas-im-tv-liv-ccf5.html

https://ayf.com/ayf/cll/Scot-v-Slov-liv-kamran-virgin00.html

https://ayf.com/ayf/cll/Scot-v-Slov-liv-kamran-virgin01.html

https://ayf.com/ayf/cll/Scot-v-Slov-liv-kamran-virgin02.html

https://ayf.com/ayf/cll/Scot-v-Slov-liv-kamran-virgin03.html

https://ayf.com/ayf/cll/Scot-v-Slov-liv-kamran-virgin04.html

https://ayf.com/ayf/cll/Scot-v-Slov-liv-kamran-virgin05.html

https://ayf.com/ayf/cll/Scot-v-Slov-liv-kamran-virgin06.html

https://ayf.com/ayf/cll/Scot-v-Slov-liv-kamran-virgin07.html

https://ayf.com/ayf/ten/Thiem-v-Tsitsipas-liv-Mara-de000.html

https://ayf.com/ayf/ten/Thiem-v-Tsitsipas-liv-Mara-de001.html

https://ayf.com/ayf/ten/Thiem-v-Tsitsipas-liv-Mara-de002.html

https://ayf.com/ayf/ten/Thiem-v-Tsitsipas-liv-Mara-de003.html

https://ayf.com/ayf/ten/Thiem-v-Tsitsipas-liv-Mara-de004.html

https://ayf.com/ayf/ten/Thiem-v-Tsitsipas-liv-Mara-de005.html

https://ayf.com/ayf/ten/Thiem-v-Tsitsipas-liv-Mara-de006.html

Benchmark and Results

As a benchmark tool, I decided to use Apache Bench. It is a simple command-line tool that is pre-installed on most systems (except for Windows).

ab -n 10000 -c 100 <url>

The -n 10000 are the requests we send in total, -c 100 stands for the connections we open at the same time — to really heat up the server.

Apache Bench then outputs some data as a result. The most important ones are listed below.

The more requests per second the better, the same applies to the transfer rate.

The less time per request, the better — the single request should be processed as fast as possible.

First I tested the native server, which is the one without Express.

Benchmark 1:

Requests per second: 10882.52 [#/sec] (mean)

Time per request: 9.189 [ms] (mean)

Time per request: 0.092 [ms] (mean, across all concurrent requests)

Transfer rate: 988.35 [Kbytes/sec] received

Benchmark 2:

Requests per second: 10876.13 [#/sec] (mean)

Time per request: 9.194 [ms] (mean)

Time per request: 0.092 [ms] (mean, across all concurrent requests)

Transfer rate: 987.77 [Kbytes/sec] received

Benchmark 3:

Requests per second: 10928.75 [#/sec] (mean)

Time per request: 9.150 [ms] (mean)

Time per request: 0.092 [ms] (mean, across all concurrent requests)

Transfer rate: 992.55 [Kbytes/sec] received

Now follows the Express.js API.

Benchmark 1:

Requests per second: 4998.91 [#/sec] (mean)

Time per request: 20.004 [ms] (mean)

Time per request: 0.200 [ms] (mean, across all concurrent requests)

Transfer rate: 454.00 [Kbytes/sec] received

Benchmark 2:

Requests per second: 5076.82 [#/sec] (mean)

Time per request: 19.697 [ms] (mean)

Time per request: 0.197 [ms] (mean, across all concurrent requests)

Transfer rate: 461.08 [Kbytes/sec] received

Benchmark 3:

Requests per second: 5249.16 [#/sec] (mean)

Time per request: 19.051 [ms] (mean)

Time per request: 0.191 [ms] (mean, across all concurrent requests)

Transfer rate: 476.73 [Kbytes/sec] received

The pure Node.js implementation of the server, completely without a framework like Express.js is much faster.

At first sight, I couldn’t believe it, and again I made sure that I created the same conditions for both servers.

So I ran the benchmark many many times — but the result remains the same.

I then ran the same benchmark on my Raspberry Pi 3B — just to see if the differences there were as huge.

While the native server is almost twice as fast in the benchmark on my MacBook Pro, the native server on the Raspberry Pi is only about 25% faster.

However, there is a significant difference — Express does not come close to the performance of a simple Node.js server in any benchmark.

Personally, I had expected Express.js to be slower — but not that the difference is sometimes so noticeable. In the end, Express.js takes a detour and builds on the HTTP module of Node.js, which we used for the native server.

Summing up

Should we learn from this to never use Express.js again? No, definitely not. Express.js is great — it makes developing backend applications very easy.

Performance at any price does not always make sense — after all, an Express app is also much easier to maintain and faster to develop, which can cost and save time on the other side.

The documentation and resources found on the Internet for Express alone are numerous and well explained.

Sending 10000 requests to a server in such a short time is also a rather unrealistic scenario — of course, the response time with Express is also higher, but under normal circumstances, this should not cause any problems for anyone.

Thank you for reading!

Here is more about web framework performance — Let‘s see what Fastify is able to do:

More about Express.js:

Join my mailing list to stay in touch