// Require Express
const express = require("express");
//require path for pathname in the folder
// __dirname is the directory name
// path.join(__dirname, *path in folder*)
const path = require('path');
//get method
//get (*url path*, ())
app.get('*url path*', (req, res) => {
//for sendingFile (rendering the file)
res.sendFile(path.join(_dirname, 'sample.html'))
})
//get with json
app.get ('*url path*', (req, res) => {
//with status
res.status(404).json({msg: 'Page not found 404l;'})
res.status(200).json({*json object to response*})
})
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