Routing
Routing is the process of handling an HTTP request that defines which kind of response will be sent to the client on which particular request. In Node JS, we have a module called http to create a server, where we create a server using http.createServer and pass a callback function to http.createServer, where we get requests and responses as s parameter and using if else and URL, we setup routes.
Node JS:
if (method === 'GET' && url === '/') {
res.end('Hello, World!');
}
While in Express JS, routing and creating servers is an inbuilt feature, we don’t need to setup if else statements to setup routes. We can directly use the simple methods of Express JS to setup routes.
Express JS:
app.get('/', (req, res) => { res.send('Hello, World!'); });
Unique features of Express JS
Express.js is known for its simplicity and flexibility which comes with various features that helps you to build efficient and scalable web applications. It makes it easier to organize your application’s functionality with middleware and routing. It adds helpful utilities to Node.js HTTP objects and facilitates the rendering of dynamic HTTP objects.
Let’s dive into some of the unique features of Express.js along with its examples.
Table of Content
- Routing
- Middlewares
- Error Handling
- Request & Response Object
- Body Parsing