Remove Extension for URL and 404 Error in node js

 const express=require('express');


const path=require('path');
const app=express();


const publicPath=path.join(__dirname,'public');
// console.log(publicPath);

// app.use(express.static(publicPath));

app.get("",(_,resp)=>{
    resp.sendFile(`${publicPath}/index.html`);
});


app.get("/home",(_,resp)=>{
    resp.sendFile(`${publicPath}/home.html`);
});


app.get('/about',(_,resp)=>{
    resp.sendFile(`${publicPath}/about.html`);
})


app.get('*',(req,resp)=>{
    resp.sendFile(`${publicPath}/nopage.html`);
})

app.listen(4000);

Post a Comment

0 Comments