1

I want to retrieve various request params in express sent to me by angular but I keep on getting 404 error: Code angular controller:

var config = {
     params: { userid: "userffvfid ",
                pass:"abcd"
            }};

$http.get('/erai',config).success(function(response) {
    console.log("I got the data I requested");
    $scope.therapist_list = response; });

Node js/Express js code:

app.get('/erai',function(req,res){
    console.log("got request");
    console.log(req.params.userid);
    console.log(req.params.pass);
    res.send("hello");
});

How do i access the params properly and respond to it properly w/o getting 404 error?

1
  • Open Chrome console, log XHR requests and check if You are sending correct req. Open the API in new tab/curl/wget and check if node server is responding. Check in server logs Which API is being called. When in doubt, log everything. Commented Feb 11, 2016 at 7:30

1 Answer 1

4

When making a get request like that any payload will be appended in the url.

So the final request url will be something like

http://www.example.com?user=John&password=Doe

To access those variables in express use the req.query object

in your case

var userid = req.query.userid
var pass = req.query.pass

If you go the POST way your data will be in the payload You will have to use a body parser middleware and then access the data with req.body

Sign up to request clarification or add additional context in comments.

2 Comments

I dint get the details what changes should I make in my express controller
make the config object just var config = {userid: 'id, pass: 'pass'} and then in your controller access them with req.query.userid and req.query.pass

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.