I'm running Sails.js v0.11.0 in NodeJS 5.12.0.
I sometimes run into a severe error, which causes my whole node js to crash. For example this code in a Sails controller
module.exports = {
fooFunction: function () {
console.log("Starting to do a silly thing");
postgresClient.connectClient(function(err, client) {
client.query("SELECT * FROM my_table WHERE id = $1", [req.user], function(err, result) {
});
});
},
}
results in
client.query("SELECT * FROM my_table WHERE id = $1", [req.user], function(err, result) {
^
ReferenceError: req is not defined
I'm also wondering why this error - unlike many others - is not caught somehow and does not result in something like
error: Sending 500 ("Server Error") response:
TypeError: Cannot read property 'user' of undefined
while the app keeps running.
But that's not my point.
My point is: How can I log this severe error message which causes my app to crash into a file?
It's not included in my standard sails.log file, where all "normal" Sails errors go in. Nor does it get logged if I change the standard output to a file running my app with the command node app.js > myfile.log
. In this case, the content of myfile.log
is just
[32minfo[39m: Sails <| .-..-.
[32minfo[39m: v0.11.0 |\
[...]
Starting to do a silly thing
and then it stops. The actual error is not there. It's just on my console. And this is very annoying when trying to debug a remote app running on a headless system. So, how can I get those errors into a log file?