Here’s the code syntax for dynamic routing and server creation in express JS :
const express = require("express");
const app = express();
app.get("/", (req, res) => {
res.send("This is the homepage");
});
app.get("/about", (req, res) => {
res.send("This is the about page");
});
app.listen(8000, () => {
console.log("Server connected successfully");
});
Here’re the steps involved:
- First require express
- Create server on the port (localhost:8000)
- define the routes on app.get