Express static file and pug use in nodejs

technical talkiess
0

 const express = require("express");

const path = require("path");

const app = express();
const port = 80;
app.use('/static',express.static('static'));
// pug template engine set
app.set('view engine', 'pug')
// path location check
app.set('views', path.join('views'));

// send varaible and message in the function
app.get('/demo', (req, res) => {
    res.render('demo', { title: 'Hey Vishal', message: 'Hello How Are you Bro' })
  })

app.get("/", (req,res) =>{
        res.status(200).send("This is the test code");
});
app.get("/about", (req,res) =>{
    res.send("This is the About code");
});
app.post("/contact", (req,res) =>{
    res.status(404).send("This is the contact code ths");
});
app.listen(port,()=>{
console.log("port is running");
});


static/index.js
console.log("done");

views/demo.pub

html
  head
    title= title
  body
    h1= message
Tags

Post a Comment

0Comments

Thanks you for commenting your questions. I will see question and respond you.

Post a Comment (0)