使用 npm start 从云存储桶中不断循环下载 google 个云存储文件

Dowload google cloud storage files from cloud bucket continuously looping when using npm start

我正在尝试从 bucket.The 下载到 google 云存储日志,文件仅在 linux 中使用节点 XXX.js 时下载一次。当我使用 npm start 时,它会不停地下载相同的文件。我可以知道背后的原因吗?

正在尝试添加 process.exit(o) 无效

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);

Given the description you're given, my hypothesis is that when using npm start, it will be running the same script x times, whereas node foo.js will run the script only once. npm start runs an arbitrary command specified in the package's "start" property of its "scripts" object. If no "start" property is specified on the "scripts" object, it will run node server.js.

有关 npm start 的更多信息 here

您还可以查看了解更多详情。

Answer: I solved the problem by changing the config.yml watch --> false. Since I download the file to the directory and watch detect file changes. Hence, it keep reloading the program.