1.

Are there any alternatives to Express.js?

Answer»

Yes there are many alternatives to Express.js and some of them are even better then Express.js. ExpessJS was released around the same time as Node.js i.e., in 2010. So, it has become the de-facto framework for Node.js.  

But since JAVASCRIPT added a lot of exciting and easy to use features with ES6 in 2015, the Express.js framework was not able to use it well. One such FEATURE is async-await which is not that easy to use in Express.js. But the new frameworks like Koa, Fastify implement such features very well. We will look into two POPULAR Express.js alternatives NEXT
 
Fastify - As the name suggests it’s a Fast framework for Node.js, which can serve up to 30 thousand requests PER second. It comes with async-await support out of the box, which can be easily used in the code. We can extend it via hooks and plugins. Fastify is also TypeScript ready, in which you can use TypeScript out of the box.  

Below is a small example to create a simple GET route in Fastify. We are using async-await through which we can handle promises and errors better. For the below code to work, we need to install Fastify in our Node application by below command. 

 npm i fastify 

Now, we can go to http://localhost:3000/ and see the correct output.

Koa - It is a modern and new framework for Node.js. Infact the Koa framework is created by some of the people in the Express.js team. It has been built ground up to use modern ES6 features like async-await and generators. One of Koa’s drawbacks is that it doesn’t come with an inbuilt router, and we need to install an external library of koa-router. 

So, we need to add these packages to a Node.js application, in order to use Koa. 

npm install koa@2.13.1 @koa/router@10.0.0 

Now, we can go to http://localhost:8080/  and see the correct output. 



Discussion

No Comment Found