0

If I need to post a data from a controller to my main server.js, I usually do it like this:

$http.post('/auth/signup', user);

This goes from a controller

app.post('/auth/signup', function(req, res, next)

and this is function with req parameter's I'll catch. The question is how to do it backwards? Does express's instance provide a method to make a request by url? Does $http or something provide a method to catch a data?

user3081123
  • 425
  • 6
  • 15

2 Answers2

1

As I said in the comment, you can use $http's success callback to "fetch" whatever came from the server:

$http.post('/auth/signup', user).success(function(resp) {
    console.log(resp); // data from res.send is here
});
Shomz
  • 36,161
  • 3
  • 52
  • 81
0

You can't on a standard application. The standard way the web works is:

  1. Application sends a request to a server
  2. Server responds to that request
  3. Application processes the response and displays some action to the user

In order to invert the workflow you would have to make your application become a server, i.e. actively listen to some port on the computer, or leave a persistent connection using websockets. This is possible, but probably not what you are looking for (I've been working web for a while and never needed this).

Look here for more info on the second option Is there some way to PUSH data from web server to browser?

Community
  • 1
  • 1
Pablo Mescher
  • 21,069
  • 6
  • 28
  • 31