“Enrutadores expresos” Código de respuesta

Archivo de enrutador expreso

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

enrutamiento expreso

app.get('/example/b', function (req, res, next) {
  console.log('the response will be sent by the next function ...')
  next()
}, function (req, res) {
  res.send('Hello from B!')
})
Purple Team

Enrutadores expresos

const birds = require('./birds')

// ...

app.use('/birds', birds)
ADEFOLAHAN AMORI

Parámetros de ruta expresa

Route path: /flights/:from-:to
Request URL: http://localhost:3000/flights/LAX-SFO
req.params: { "from": "LAX", "to": "SFO" }
Motionless Mouse

enrutador expreso ()

express.Router( [options] )
Careful Cormorant

express () vs express.router ()

var express = require('express');

var router = express.Router();

router.get('/', function(req, res) {
    res.send('GET handler for /dogs route.');
});

router.post('/', function(req, res) {
    res.send('POST handler for /dogs route.');
});

module.exports = router;
Clean Crane

Respuestas similares a “Enrutadores expresos”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código