Understanding and working with Express Route
Routes in Express
Here is an example how we create multiple routes in express :
const express = require("express");
const app = express();
const PORT = 3000;
app.get("/", function(req, res){
res.send("<h1>Hello Express</h1>")
});
app.get("/contact", function(req, res){
res.send("Contact : <b>mayacr62@gmail.com</b>");
});
app.get("/about", function(req, res){
res.send("<h3>Hello, I am Mayaram Chaudhary. Click Me <a href='github.com/maya-cx'>GitHub</a>");
})
app.listen(PORT, function(){
console.log("Server started on port "+PORT);
});
Struggling refreshing page everytime ?
Install NodeMon package which monitors the changes in you source and restart server automatically.
> npm install nodemon
To start nodemon
> nodemon file.js and hit enter
Comments
Post a Comment