프로그래밍/Node.js
Node.js) Express 미들웨어1
이불이!
2019. 4. 24. 13:15
728x90
대충 작성하였던 미들웨어 부분을 지우고 다시 새로 작성하는중.
const express = require('express') ;
const app = express() ;
console.log('첫번째 미들웨어') ;
next() ;
}) ;
console.log('두번째 미들웨어') ;
next() ;
}) ;
console.log('세번째 미들웨어') ;
res.send('Hello express') ;
}) ;
//왜 세번째 미들웨어에서는 next를 안붙여도 되는걸까?
//바로 res.send 코드 때문에다.
res.send('Hello get') ;
}) ;
//http에서 get 요청이고 '/'로 들어오는 것만 받는다.
res.send('Hello users') ;
}) ;
}) ;
app.delete('/users', (req, res) => {
}) ;
//use와 나머지 get,post...(라우팅 미들웨어)등의 차이는 use는 모든 요청을 다 받지만,
//나머지는 주소와 일치하는 요청만 걸러받는다.
module.exports = app ;
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5; text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs |