- using middleware
- neat req and res
- routing
- handle html pages

const app = express();
app.use((req, res, next) => {
res.send();
next();
});
app.listen(3000);
// router
const router = express.Router();
router.post('/product', (req, res, next) => {
});
app.use(productRoutes);
app.use((req, res, next) => {
res.status(404).send('<h1>Page not found</h1>');
});
const path = require('path');
router.get('/', (req, res, next) => {
res.sendFile(path.join(__dirname, 'views', 'shop.html'))
});
express implementation for server:
call the listen method on the server object.
Q. How to add prefix to routes?
app.use(‘/admin’, adminRoutes)
send and sendFile method.
module.exports = path.dirname(require.main.filename)
Above gives the root file name which started the application. This works on alloperating_systems
Serving files statically
app.use(express.static(path.join(__dirname, ‘public’)))