Getting my hand dirty in Sail.js (and node).
Versions
$ sails --version
1.2.4
$ node --version
v12.16.1
My first sails controller (an example) is as follows:
// MyController
// MyController.js
module.exports = {
sum_it: function (a, b) {
return (a + b);
},
minus_it: function (a, b) {
return (a - b);
},
process_it: function (req, res) {
let i = 12;
let j = 4;
do_what = "sum"; //this will be an input extracted from req
if (do_what == "sum") {
let result = this.sum_it(i, j); //"this" doesn't work????
} else {
let result = this.minus_it(i, j); //"this" doesn't work????
}
console.log(result);
return res.send(result);
}
};
My intention is to have few functions defined within that controller itself as they would be ONLY used under this controller. I used this.sum_it(i, j) this.minus_it(i, j) and both of them don't work.
What is the best way to have multiple functions in the controller and call them within that controller file (assuming those functions are too specific to that controller and hence, no need to take them out and put in the other helper files)?