How to Send Data to API in JavaScript Node – Best Practices? or What’s the Right Way to Send Data to

20 Replies, 890 Views

If you’re struggling with how to send data to api in javascript node, try `got`—it’s like `axios` but lighter and more modern.

```javascript
const got = require('got');

(async () => {
try {
const { body } = await got.post('https://api.example.com', {
json: { hello: 'world' }
});
console.log(body);
} catch (error) {
console.log('Yikes:', error.response.body);
}
})();
```

It even streams responses! Super handy for big data.

Messages In This Thread



Users browsing this thread: 1 Guest(s)