Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

NodeJS router model

const express = require('express');
const router = express.Router();

// Get to home controller req and res function
router.get('/', app.home);
//---- Inside controller.js
const home = (req, res) => {
  res.setHeader('Cache-Control', 'no-cache');
  res.status(200).json({
    status: 'Ok'
  });
};
//----


// NOT FOUND Middleware
router.use((req, res) => {
  res.status(404).json('not found');
});

module.exports = router;
 
PREVIOUS NEXT
Tagged: #NodeJS #router #model
ADD COMMENT
Topic
Name
2+5 =