Express JS routing

Express JS
Express JS routing

In this tutorial you will learn about Express JS Routing.

What is Express JS routing

Routing is used to determine how an application responds to a client request to a particular URL and a specific HTTP request method such as GET, POST, PUT, etc.

How to define an Express route

Structure of a route

app.method(path, handler)


In here app is an instance of express.


The method is an HTTP request method and method name should be lower case.

app.get(path, handler);, handler);
app.put(path, handler);
app.delete(path, handler);


The path is a URL path

app.get('/', handler);

app.get('/user', handler)

app.get('/post/hello-post', handler)


The handler is a function and it is executed when the root matched.

app.get('/', (req, res) => {
    res.send('Home page from get request')

open http://localhost:3000/ through get request

Browser Output
Home page'/', (req, res) => {
    res.send('Home page from post request')

open http://localhost:3000/ through post request

Browser Output
Home page from post request

Next isExpress JS Route Handler

Previous is – Install express and write your first app with the express

You May Also Like

Leave a Comment

Your email address will not be published. Required fields are marked *