简体   繁体   中英

Nodejs - running external process

Need to build a back-end service using node-js which does the following.

  1. Accepts file-upload from client (browser)
  2. Save the file on disk and update DB ( mongodb ) with new filename and status as saved
  3. Starts an long running process to parse the file ( written in python) and get feedback ( progress, error, success) , update DB with status feedback

How do we call # 3 from node.js - it could be system call like python parse_file.py filename

app.post('/upload',function(req,res, next){

       // what should go here to call the process

        res.writeHead(201, {'Content-type': 'text/plain'});
        res.end("File uploaded.");
    }
});

You can use require('child_process').spawn() or require('child_process').exec() to spawn a child process. The docs for those can be found at https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_child_process_spawn_command_args_options

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM