Node.js cURL Equivalent

npm install --save axios
curl https://checkip.amazonaws.com
const axios = require('axios');
async function run(){
var options = {
method: 'GET',
url: 'https://checkip.amazonaws.com',
};
axios(options)
.then(function (response) {
// handle success
console.log(response.data);
})
.catch(function (error) {
// handle error
console.log(error.response.data);
})
}
run();
curl -s \
--form-string "token=abc123" \
--form-string "user=user123" \
--form-string "message=hello world" \
https://api.pushover.net/1/messages.json
npm install qs
const axios = require('axios');
const qs = require('qs');

async function run(){
var data = {
'token':'abc123',
'user':'user123',
'message':'hello world',
};
var options = {
method: 'POST',
headers: { 'content-type': 'application/x-www-form-urlencoded' },
data: qs.stringify(data),
url: 'https://api.pushover.net/1/messages.json',
};
axios(options)
.then(function (response) {
// handle success
console.log(response.data);
})
.catch(function (error) {
// handle error
console.log(error.response.data);
})
}
run();

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kevin FOO

Kevin FOO

A software engineer, a rock climbing, inline skating enthusiast, a husband, a father.