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

2

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

if my data is all in a file, how would I input that file into the body field?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.