I am using request-promise to fetch data from an api. I need to write the results to a json file. Following code doesn't write anything to the file.
var rp = require('request-promise');
rp(empOptions)
.then(function (repos) {
employees= repos;
return new Promise(function(resolve, reject) {
fs.writeFile('../employees.json', JSON.stringify(employees), function(err) {
if (err) reject(err);
});
});
})
.catch(function (err) {
// API call failed...
});
I have tried this also, but that didn't worked out either.