route 파일을 별도로 관리하려면 routes
폴더가 필요
그 안에 비슷한 라우트들은 별도의 js파일로 관리
분리된 js 파일
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;
var birds = require('./birds');
...
app.use('/birds', birds);
router.use(적용할 미들웨어);
router.use('미들웨어 적용할 특정경로', 적용할 미들웨어);
multer
라이브러리를 설치하고 사용let multer = require('multer');
var storage = multer.diskStorage({
//파일이 저장될 경로
destination: function(req, file, cb) {
cb(null, './public/image')
},
filename: function(req, file, cb) {
cb(null, file.originalname)
}
});
var upload = multer({storage : storage});
const 찾을문서 = [
{ $match: { fullDocument.name : 123 } }
];
const changeStream = db.collection('message').watch(찾을문서);
changeStream.on('change', (result) => {
console.log(result.fullDocument);
});