How to send / receive data from the client to the server?

2

How to send / receive data from the client to the server, making requests like dynamically fetching the database?

    
asked by anonymous 13.11.2014 / 18:07

1 answer

1

If you are using Express you can receive data via app.get () or app.post ()

  • app.get ()

Data passed in GET (url for example: google.com?foo=bar&animal=gato ) will be available via req.query . An example would be:

app.get('/pasta', function(req, res){
    var foo = req.query.foo;
    // etc
});
  • app.post ()

Data passed in POST is available via req.body . That is, if you have a <form action="/pasta" ... and an input: <input type="text" name="animal" /> this data can be used like this:

app.post('/pasta', function(req, res){
    var animal= req.body.animal;
    // etc
});
    
14.11.2014 / 08:44