ways

  1. sendFile
  2. path
  3. static folder
  4. template engine

sendFile

app.get('/', (req, res) => {
    res.sendFile(__dirname + '/index.html')
})

path

cross platform / \

let's create a static files with two files about and contact

app.get('/about', (req, res) => {
    res.sendFile(path.join(__dirname + '/static/about.html'))
})

app.get('/contact', (req, res) => {
    res.sendFile(path.join(__dirname + '/static/contact.html'))
})
  • you have to repeat code and styling

static foler

serve http-server live-server

template engines

  • ejs
  • pug
  • handlebars