Deidara Deidara - 1 year ago 158
Javascript Question

run terminal commands in node js

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

quickscrape \
--url \
--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.

Answer Source

I think child_process is that you need.

let exec = require('child_process').exec;
exec('quickscrape --url --scraper journal-scrapers/scrapers/peerj.json --output peerj-384 --outformat bibjson', (error, stdout, stderr) => {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download