2

I want to send my server.js (in an AngularJS controller) an set the id parameter like this:

 $http
    .get('/getCst', {
        params: {               
            id: customerID
        }
     })
     .success(function (data,status) {
          $scope.customer = data
     });

But i'm not sure if this is the correct way and what to write in the Node.js server.js:

app.get('/getCst', function (req, res) {

        console.log(//how do i get the id sent by the client?);     
});
user3061943
  • 99
  • 1
  • 11
  • possible duplicate of [How to get GET (query string) variables in Node.js?](http://stackoverflow.com/questions/6912584/how-to-get-get-query-string-variables-in-node-js) –  Jan 13 '15 at 09:21
  • its not a duplicate. my url looks like `127.0.0.1:8080/cust/534543` 534543 is the id. I cant get it with req.query.id – user3061943 Jan 13 '15 at 09:23
  • What does `/cust/534543` have to do with `/getCst`? Your AngularJS code will *not* make a GET request to `/cust/534543`, not evetn to `/getCst/534524`. It will call `/getCst?id=534534`. https://docs.angularjs.org/api/ng/service/$http –  Jan 13 '15 at 09:27
  • Use `req.query.id`. Ref : http://stackoverflow.com/questions/17007997/how-to-access-the-get-parameters-in-express-js-or-node-js – themyth92 Jan 13 '15 at 09:34

3 Answers3

3

It's my solution

app.get('/getCst/:id', function (req, res, next) {

        var id = req.params.id;    
});
MaximeF
  • 4,913
  • 4
  • 37
  • 51
0

Try this:

app.get('/getCst:id', function (req, res) {

        console.log(req.param('id'));     
});
squiroid
  • 13,809
  • 6
  • 47
  • 67
0

app.get('/getCst', function (req, res) {

    var id = req.query.id;   

});

dev verma
  • 671
  • 1
  • 9
  • 18