I'm trying to download to google cloud storage logs from bucket.The files only download once when using node XXX.js in linux. When I use npm start, it non-stop downloading the same files. May I know the reason behind ?
Trying to add process.exit(o) not working
async function main() {
await
client
.bucket(bucketName)
.getFiles(options)
.then(results => {
const files = results[0];
console.log('Files:');
files.forEach(file => {
const formatFileName = file.name.replace( /\//g ,'_');
var new_str = formatFileName.split(":")[0];
fs.open(new_str+'.json', 'w', function (err, file) {
if (err) throw err;
console.log('File is opened in write mode.');
fs.close(file, function () {
console.log('File is closed.');
})
});
const destOptions = {
destination: +new_str+'.json'
};
file.download(destOptions);
fs.rename(new_str+'.json', new_str+'.txt', function(err) {
if ( err ) console.log('ERROR: ' + err);
});
console.log(file.name);
return code;
});
})
.catch(err => {
code = 1;
console.error('ERROR:', err);
});
}
main().then((res) => {
console.log('here');
return process.exit(0);
}).catch(console.error);