What is Express.js?
Express.js is a one of the most popular Node.js based web framework which helps in creating server-side web applications faster and smarter.
Most common usecase of express.js is API development.
Why should I use Express.js when there’s already Node.js?
While it’s possible to build a web app using Node.js only but
Express.js simplifies the development process by providing a thin layer of fundamental Web application features, without obscuring Node.js features.
Example:
Express.js v/s Node.Js
- Sending an image is complex in Node but easily done in Express.
- In Node, the route handler is a large monolith but Express enables more modular design and maintainable code.
- Node can be used as the app server for your web application but Express comes with a number of “middleware” software that implement out-of-the-box solutions for typical web app requirements.
The term Middleware defines anything you put in the middle of one layer of the software and another. Express application is essentially a series of middleware function calls which have access to both request and response object.
Most useful or recommended middleware for Express.js are as below
- body-parser: To parse HTTP request body.
- compression: Compresses HTTP responses.
- cookie-parser: Parse cookie header.
- cookie-session: Establish cookie-based sessions.
- cors: Enable Cross-Origin Resource Sharing (CORS).
- csrf: Protect from Cross-Site Request Forgery (CSRF) exploits.
- errorhandler: Development error-handling/debugging.
- morgan: HTTP request logger. Alternatives are winston and bunyan.
- timeout: Set a timeout period for HTTP request processing.
- helmet: Helps secure your apps by setting various HTTP headers.
- passport: Authentication using OAuth, OpenID and many others.
- express-async-handler: For Async/await support. An alternative is @awaitjs/express.
- express-cluster: Run express on multiple processes.
Key benefits of ExpressJS Framework
- MEAN or MERN Stack: We know In today world, every frontend community members want to be in Full Stack role and presence of ExpressJS in MEAN(MongoDB, AngularJS, ExpressJS, NodeJS) or MERN(MongoDB, ReactJS, ExpressJS, NodeJS) stack motivate and helps frontend developers to step into new role.
- Ease of coding : NodeJS alone is not a rocket science, ExpressJS helps to cut down programming time in half. Also since NodeJS and ExpressJS are written in JavaScript, a very easy language to learn and manipulate, the framework is highly scalable and flexible. You can build websites, web application, and even cross platform compatible mobile apps.
- Large bundle of features to support all you need in your development tasks
- Robust routing facility for routing your web requests to the function
- Organized platform for coding APIs
- Supported with most of the other supporting libraries and plugins
- Secured and maintained consistently to keep up with the standards
- Great community support
I hope you have enjoyed this article. To make this article more interesting, your feedback is very valuable for me. Please reach me @LinkedIn
See next : Hello World program in Express JS
Stay tuned for more articles like: ExpressJS CRUD Implementation and documentation with Swagger