π μ΄νν μ½λ© μκ° 2hour
ππΌ -
ππΌ -
Middleware
Express is a routing and middleware web framework. Middleware functions are functions that have access to the request object, the response object, and the next middleware function in the application's request-response cycle.
Morgan
Morgan helps us log HTTP requests information to our terminal.
const morgan = require('morgan');
app.use(morgan('tiny'));
//app.use runs on every single request
Next
const morgan = require('morgan');
app.use(morgan('common'));
app.use((req, res, next) => {
console.log('1 : This is my first middleware');
next();
console.log('2 : This is my first middleware - after calling next()');
});
app.use((req, res, next) => {
console.log('3 : This is my second middleware');
next();
});
// 1 - 3 - 2
app.use((req, res, next) => {
console.log('1 : This is my first middleware');
return next();
console.log('2 : This is my first middleware - after calling next()');
});
app.use((req, res, next) => {
console.log('3 : This is my second middleware');
return next();
});
// 1 - 3