diff --git a/bin/cli.js b/bin/cli.js index f99ef62..687f5d9 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -80,8 +80,8 @@ require('yargs') }, filetype: { default: 'csv', - choices: ['csv', 'json', 'all', ''], - describe: "Type of the output file where the data will be saved. 'all' - save data to the 'json' and 'csv' files", + choices: ['csv', 'json', 'all', 'stdout', ''], + describe: "Type of the output file where the data will be saved. 'stdout' - print json to stdout. 'all' - save data to the 'json' and 'csv' files", }, sort: { default: false, diff --git a/lib/Amazon.js b/lib/Amazon.js index d272d74..75901de 100644 --- a/lib/Amazon.js +++ b/lib/Amazon.js @@ -243,7 +243,7 @@ class AmazonScraper { if (this.cli) { spinner.stop(); } - if (this.fileType && this.cli) { + if (this.fileType && this.cli && this.fileType !== "stdout") { console.log(`Result was saved to: ${this.fileName}`); } return { @@ -310,6 +310,9 @@ class AmazonScraper { async saveResultToFile() { if (this.collector.length) { switch (this.fileType) { + case 'stdout': + console.log(JSON.stringify(this.collector)); + break; case 'json': await fromCallback((cb) => writeFile(`${this.fileName}.json`, JSON.stringify(this.collector), cb)); break;