0

I have the curl command here which is working as I want:

curl -X POST -H "Content-Type: application/json" -d @cats.json http://localhost:8080

And I would like to get help on translating this into nodejs

I currently have localhost set up and my goal is to display data stored in a JSON file. I currently copy and paste the data into postman and post the data to the localhost but I want to not use postman. The curl command was useful but I want to incorporate it into my code.

I've tried

var request = require('request');
request.post({
  headers: {'content-type' : 'application/json'},
  url:     'http://localhost/8080',
  body:    "someData"
}, function(error, response, body){
  console.log(body);
});

I've tried this but it doesn't provide the same outcome as the curl command does where the data appears in my localhost

user269867
  • 3,266
  • 9
  • 45
  • 65
Kisuna97
  • 37
  • 7

1 Answers1

1

In postman, you can export NodeJS request code out:

enter image description here

Click on Code Then select NodeJS -> Request. Copy to Clipboard

enter image description here

Matt Kuhns
  • 1,328
  • 1
  • 13
  • 26