I am using node 12 and npm request module version 2.88.0. While making a request to an API call , it is giving me error as options.uri is a required parameter. Also i had tried to change the url to uri but still getting same.
apiURL is defined as in
{
"Config": {
"dev": {
"apiURL": "https://apiURL.com"
}
}
}
and config where its fetched on the basis of what enviornment is it running
const config = require('./default');
var dev = config.Config.dev;
var prod = config.Config.prod;
module.exports.configure = function () {
var environment = 'dev'; //process.env.NODE_ENV;
var config = {};
switch (environment) {
case 'prod':
config = {
apiURL: prod.apiURL,
//etc
}
return config;
case 'dev':
config = {
apiURL: dev.apiURL,
//etc
}
return config;
default:
var error =
'No Environment Configured.';
throw error;
}
};
Here is the actual code part while making the api call
async function callAPI(id, pass) {
request(
{
url: apiURL,
method: 'POST',
body: {
id,
pass,
},
json: true,
},
async function (error, response, body) {
if (response && response.statusCode == 200) {
logger.log(
INFO,
JSON.stringify({
Module: 'API ',
Response: `${JSON.stringify(body)}`,
}),
);
return Promise.resolve(response);
} else {
return Promise.reject(response);
}
},
);
}