-2

I'm trying to write a web crawler program using quickscrape, after I type

quickscrape \
  --url https://peerj.com/articles/384 \
  --scraper journal-scrapers/scrapers/peerj.json \
  --output peerj-384
  --outformat bibjson

and hit the "Enter" in my terminal, the library will generate the result from the crawler and put them into a folder.

Now I want to write a javascript progarm so that is will call these terminal commands for me, but I am not sure how to interact with terminal in node.js.

Community
  • 1
  • 1
Deidara
  • 667
  • 2
  • 13
  • 28
  • Possible duplicate of [Execute and get the output of a shell command in node.js](https://stackoverflow.com/questions/12941083/execute-and-get-the-output-of-a-shell-command-in-node-js) – Damjan Pavlica Jul 17 '18 at 12:58

1 Answers1

7

I think child_process is that you need. https://nodejs.org/api/child_process.html

let exec = require('child_process').exec;
exec('quickscrape --url https://peerj.com/articles/384 --scraper journal-scrapers/scrapers/peerj.json --output peerj-384 --outformat bibjson', (error, stdout, stderr) => {
    //...
})
Eugene Tsakh
  • 2,777
  • 2
  • 14
  • 27