How to Use Middlewares in Node

In this article, we would be seeing middlewares in NodeJS and how we would use them in our application. What are middlewares in Node.Js? Middlewares are functions used in connecting a bunch of isolated systems to interact and perform certain tasks. For example, think of a switch as a component and bulb as another independent component where a wire acts as a middleware to connect these both and give us the required output (In this case, electricity to light the bulb).

Generate a NodeJS Flamechart

Here’s how you can generate a Node flame graph with linux perf(1). Note that perf(1) needs to run as root, but the perf.map file node generates might be owned by a different user. If that’s the case, you’ll need to change its ownership to root as well — otherwise perf(1) will not be able to use it to translate JS stack frames. $ uname -a Linux demo 3.2.0-74-virtual #109-Ubuntu SMP Tue Dec 9 17:04:48 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux