I'm trying to develop a currency converter using node.js. I'm using 'request' to make HTTP requests. Currently in my code, the query strings (q=1, from=USD, to=LKR) are hard coded in the url. I want to know how to pass those strings as arguments in order to make it dynamic and get as many currency formats as I want.
var request = require('request');
const options = {
url : "https://currency-exchange.p.rapidapi.com/exchange?q=1&from=USD&to=GBP",
headers: {
'x-rapidapi-host': 'currency-exchange.p.rapidapi.com',
'x-rapidapi-key': 'b13c4f3d67msh8143a7f1298de7bp1e8586jsn4453f885a4e7'
}
}
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
console.log(response.body);
}
}
request(options, callback);