Ugh, 404s are the worst. 😤 For how to send data to api in javascript node, I’d recommend the `http` module if you want no dependencies, but it’s kinda verbose.
Here’s a barebones snippet:
```javascript
const http = require('http');
const data = JSON.stringify({ foo: 'bar' });
const req = http.request('http://api.example.com', {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
}, (res) => {
let response = '';
res.on('data', (chunk) => response += chunk);
res.on('end', () => console.log(response));
});
req.on('error', (e) => console.error('RIP:', e));
req.write(data);
req.end();
```
Pro tip: Use `try/catch` if you’re mixing async/await!
Here’s a barebones snippet:
```javascript
const http = require('http');
const data = JSON.stringify({ foo: 'bar' });
const req = http.request('http://api.example.com', {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
}, (res) => {
let response = '';
res.on('data', (chunk) => response += chunk);
res.on('end', () => console.log(response));
});
req.on('error', (e) => console.error('RIP:', e));
req.write(data);
req.end();
```
Pro tip: Use `try/catch` if you’re mixing async/await!
