Routes in Express JS Examples

routes_express_thumb

Express routes helps to route incoming request to specific pages. There will be request and response parameters.

Below you can find a sample code the routes the request to the

/ – root directory

/contact — contact page

/about — about page

Code

const express = require("express");
const app = express();

app.get("/", function(req, res){
    res.send("Hello World");
})

app.get("/contact", function(req, res){
    res.send("Contact me at [email protected]");
})

app.get("/about", function(req, res){
    res.send("Smartcodehelper helps with code references and sample codes.")
})

app.listen(3000, function(){
    console.log("server started at port 3000");
});

About the Author: smartcoder

You might like

Leave a Reply

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