Home » Express.js Routing

Express.js Routing

by Online Tutorials Library

Express.js Routing

Routing is made from the word route. It is used to determine the specific behavior of an application. It specifies how an application responds to a client request to a particular route, URI or path and a specific HTTP request method (GET, POST, etc.). It can handle different types of HTTP requests.

Let’s take an example to see basic routing.

File: routing_example.js

ExpressJS Routing

You see that server is listening.

Now, you can see the result generated by server on the local host http://127.0.0.1:8000

Output:

This is the homepage of the example app.

ExpressJS Routing

Note: The Command Prompt will be updated after one successful response.

ExpressJS Routing

You can see the different pages by changing routes. http://127.0.0.1:8000/enrolled_student

ExpressJS Routing

Updated command prompt:

ExpressJS Routing

This can read the pattern like abcd, abxcd, ab123cd, and so on.

Next route http://127.0.0.1:8000/abcd

ExpressJS Routing

Next route http://127.0.0.1:8000/ab12345cd

ExpressJS Routing

Updated command prompt:

ExpressJS Routing

Next TopicExpress.js Cookies

You may also like