A
A
Anton Ulanov2016-02-07 01:43:19
Node.js
Anton Ulanov, 2016-02-07 01:43:19

How to post raw data to node.js server?

Good time of the day. I wrote a small server in node.js, but I can't figure out how the post method is passed to the server. There is a Route

.post(function(req, res) {
    
    var device = new Device();
    device.uuid = req.body.uuid;
    device.location.coordinates = req.body.location.coordinates;
    device.type = req.body.type;
    device.save(function(err) {
      if (err)
        res.send(err);
   
      res.json({ message: 'Device created!' });
    });
  })

Through Postman, I pass the data in javascript / json raw format
{
"uuid": "device 12",
"location": {
"coordinates": [-110.0, 110.20]
}
}
and the data is successfully received by the server and written to the database. the path by which the postman sends data to localhost/api/devices
I actually had a question as data through a call to localhost/api/devices/post?uuid=123&coordinates=12.12 ,11.11&type=simple as an example :) Thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg Ostovsky, 2016-02-07
@malefique

do I need to explain the difference between POST and GET? Why are there so many drug addicts on this resource?

A
Anton Ulanov, 2016-02-07
@antonsr98

what's with the drug addicts? if you do not want and do not want to help, then there is no reason for him to write about it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question