How come it cannot see the res part of my calling function?
Here is my calling function frontpageController.js
exports.getFrontpage = function(req, res) {
var priceController = require('./priceController');
var priceModel = require('../models/priceModel');
var priceTable = mongoose.model('priceModel');
var callPriceController = function() {
return new Promise((resolve, reject) => {
priceController.getPrice (
{ "body": { "propertyID": "WAT-606" } }
,function(err, data) {
console.log("HELLO!!! ");
if (!err) {
console.log("Result: " + JSON.stringify(data, null, 4));
} else {
console.log("ERR: " + err);
};
});
})};
callPriceController()
.catch(err => {
console.log("getFrontpage ERR: " + err);
//res.json({error:true,err});
})
}
Here is the controller that I want to call getData
exports.getPrice = function(req, res){
//
// Validate the data we get from router
//
console.log("priceController received: " + JSON.stringify(req.body, null, 4));
res.json({error:false,test:"hello from getPrice"});
}
And here is the console log:
GET /frontpageRoute/getFrontpage - - ms - -
priceController received: {
"propertyID": "WAT-606"
}
getFrontpage ERR: TypeError: res.json is not a function
Here is the getPrice router:
var express = require('express');
var router = express.Router();
var priceController = require('../controllers/priceController');
router.post('/getPrice', function(req, res) {
priceController.getPrice(req, res);
});
module.exports = router;
Here is the frontpage router
var express = require('express');
var router = express.Router();
var frontpageController = require('../controllers/frontpageController');
router.get('/getFrontpage', function(req, res) {
frontpageController.getFrontpage(req, res);
});
module.exports = router;
console.log(res)output?getDataand get the result{error:false,test:"hello from getData"}backcatchand gives the errorTypeError: res.json is not a functionwhen it reach theres.json({error:false,test:"hello from getData"});getData, it callsgetPrice... What am I missing?