DEV Community

Cover image for Routing in Express.js
Akhtar Hussain
Akhtar Hussain

Posted on

Routing in Express.js

Introduction

Routing refers to how an application’s endpoints (URIs) respond to client requests. Expressjs official Docs

You define routing using express app object corresponding HTTP methods POST and GET method.

For example

The following code shows an example of a very basic route.

Image description

Route Methods

A route method is derived from one of the HTTP methods and is attached and called on app object, an instance of the express class.

GET and POST Methods to the root off the app:

Image description

Route Paths

These routes defined in the above code snippet will map to:
http://localhost:3000/ when app is run locally and matching depends on whether client uses POST or GET method and vice versa.

Image description

The above route matches to http://localhost:3000/about when the app is run locally.

Top comments (0)