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});
})
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter