I have a question about my .post()
request:
const express = require('express');
const router = express.Router();
const search_controller = require('../controllers/searchController');
const result_controller = require('../controllers/resultController');
//Search Routes
router.post('/', search_controller.search_create_post);
module.exports = router;
Is it possible to add a second callback to the request in order to run both callbacks sequentially, like this:
router.post('/', search_controller.search_create_post, result_controller.result_create_post)
Do I need to use next()
inside those create functions? And can I pass data from the search_create_post
callback to the result_create_post
callback? Specifically, I would like to pass the id of the newly created Search object.
This is my current
search_controller.search_create_post
function:
exports.search_create_post = (req, res, next) => {
let newSearch = new Search({ search_text: req.body.search_text });
newSearch.save((err, savedSearch) => {
if (err) {
console.log(err);
} else {
res.send(savedSearch);
}
})
};