1
app.post("/web/suggest_oncall", function(req, res){
    function getQueryVariable(variable) {
           var query = window.location.search.substring(1);
           var vars = query.split("&");
           for (var i=0;i<vars.length;i++) {
                   var pair = vars[i].split("=");
                   if(pair[0] == variable){return pair[1];}
           }
           return(false);
    }
    console.log(getQueryVariable("list"));
});

I am trying to pull the value of "list" from the query and display it in the console. What exactly can I do for window to be recognized?

1
  • @adeneo what do I do for it to recognize then? Commented Mar 24, 2014 at 19:09

1 Answer 1

3

Seriously, there is no window on a server, but req.url should contain the current URL.

app.post("/web/suggest_oncall", function(req, res){
    function getQueryVariable(variable) {
           var url   = req.url; // gets the URL
           var query = url.split('?').pop().substring(1);
           var vars = query.split("&");
           for (var i=0;i<vars.length;i++) {
                   var pair = vars[i].split("=");
                   if(pair[0] == variable){return pair[1];}
           }
           return(false);
    }
    console.log(getQueryVariable("list"));
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.