express

PHOTO EMBED

Sun Jul 23 2023 09:16:50 GMT+0000 (Coordinated Universal Time)

Saved by @nelson22

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

// routing
app.listen(3000);
// register public folder as static so that it can be accessable
app.use(express.static('public'));

app.get('/', (req, res) => {
    //res.send('<p>This is responses.</p>');
    res.sendFile('./views/index.html', {root: __dirname});
});

app.get('/about', (req, res) => {
    res.sendFile('./views/about.html', {root: __dirname});
});

app.get('/aboutus', (req, res) => {
    res.redirect('/about');
});

app.use((req, res) => {
    res.status(404).sendFile('./views/404.html', {root: __dirname});
})
content_copyCOPY