“NodeJs router” Kode Jawaban

file router ekspres

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

// middleware that is specific to this router
router.use(function timeLog (req, res, next) {
  console.log('Time: ', Date.now());
  next();
});
// define the home page route
router.get('/', function (req, res) {
  res.send('Birds home page');
});
// define the about route
router.get('/about', function (req, res) {
  res.send('About birds');
});

module.exports = router;
Lively Loris

NodeJs router

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;
Kamyab Rouhifar

Jawaban yang mirip dengan “NodeJs router”

Pertanyaan yang mirip dengan “NodeJs router”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya