Question

I wrote the following example controller using Sails.js:

userController.js

module.exports = {
    test: function(req, res){
        console.log('test')
        res.json('test')
    }
};

When I run sails.js and send it to that route (user/test), it appears to execute that code twice and outputs test twice in my WebStorm debug window:

"test"
"test"

How do I keep Sails.js from executing the same code twice?

Was it helpful?

Solution

I couldn't reproduce your issue. I tried really hard to reproduce it.

I created the same controller you have in your question, and I ran the code -- but not in WebStorm, I ran it from the command line. Since you're using console.log("test"), I should be able to see the console output test twice if your code is doing what you're saying it's doing, however, I couldn't get that to happen:

Only output once

As you can see from the screenshot, the console output test once, and the webbrowser output a response of test, which exactly matches the code you've given:

module.exports = {
    test: function(req, res){
        console.log('test') //output test to console
        res.json('test') //output test to the response
    }
};

I can't reproduce the issue as you've shown it; and there's no indication that controller is getting executed twice.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top