Answers for "express serve a webpage"

5

express serve home page

app.use('/', express.static('public', { index: 'index.html' }));
Posted by: Guest on June-24-2021
0

express serve html

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

const app = express()

const port = process.env.PORT || 3000
const publicDirectoryPath = path.join(__dirname, '../public')

app.use(express.static(publicDirectoryPath))

app.listen(port, () => {
    console.log(`Server is up on port ${port}!`)
})
Posted by: Guest on July-31-2020

Browse Popular Code Answers by Language