Home > OS >  How to execute shell scripts on the backend of a nodejs web app?
How to execute shell scripts on the backend of a nodejs web app?

Time:09-25

I have a full stack MERN application running on a google compute engine, along with a local mongodb running on the same server. Its a CRUD application, however, I have a script that is stored in the server that I would like triggered everytime a user presses a button on the front end. (a use case would be, user enters some input that is logged into the database, and when its logged I would like a script triggered on the backend that creates a json file out of the mongodb table and uploads it to github/emails it out).

I'm not sure where to start learning this, a few google searches have led me to AJAX and child_processes, am I going in the right direction? Any resources or pointers would be great. Thank you

CodePudding user response:

If I understood the question correctly then you want to accomplish the following things:

1. Export json data from a local MongoD instance.
2. Then send that data to github or email it somewhere.

In that case I would recommend to use child process(exec, spawn, execFile, fork) to execute the mongoexport command to get .json files.

But I don't recommend using shell script to upload that data to github or email it.

Use the github api for github and use node-mailer to email the data.

To learn more about child processes read the docs here Node.js v14.x Child process docs

  • Related