nodeJs, Express получить ответ и вызвать другую функцию - PullRequest
0 голосов
/ 18 мая 2018

У меня есть post.route.js, где я упоминаю

var post = require('../controllers/post.controller');
router.route('/posts').get(post.getPosts, post.setCache);

, а мой post.controller.js имеет

exports.getPosts = function(req, res, next) {
    var qstring = postQueryString;
    getPostsDataByQuery(qstring,req,res,next);
}

function getPostsDataByQuery(queryString,req, res, next){
  logger.info('start',req.route.path);
  // some code here
  return res.json(rows);
  next();
};

exports.setCache = function(req, res, next){
    console.log('here in set function');
   cache.setExp(req, rows);
   return true;
 }

, если в setExp я веду журнал, не показывая мне

exports.setExp = function(req, data){
    console.log('here');
  }

1 Ответ

0 голосов
/ 18 мая 2018

Вы можете использовать метод next:

function getPosts(queryString, req, res, next){
  // your code
  next();
};
 function setCache(req, res) {
   cache.setExp(req.originalUrl, process.env.CACHE_POST_EXP_TIME, rows);
   return true;
 }

 router.route('/posts').get(post.getPosts, post.setCache);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...