i399exback/express-examples/express5.js
2017-04-04 15:57:10 +03:00

26 lines
500 B
JavaScript

'use strict';
const express = require('express');
const app = express();
app.get('/api/p', p1);
app.get('/api/p', p2);
app.use(errorHandler);
app.listen(3000);
function p1(request, response, next) {
console.log('p1');
next();
}
function p2(request, response, next) {
console.log('p2');
next('error from p2'); // argument makes it an error
}
function errorHandler(error, request, response, next) { // there must be 4 arguments
response.status(500).send(error.toString());
}