Allow end-user to upload and execute javascript on server side
Question: I'm studying javascript/nodeJS to develop ERP solution. I would like to allow
ERP end-users to upload their own custom scripts, so they can interact with
ERP scripts. Of course user scripts should implement pre-defined ERP API.

For example this is a feature offered by ODOO (open-ERP) using user custom
scripts writen in python.

I would like to know if full javascript stack can do the trick: is it possible
to import some uploaded js file at runtime in node.js, in order to execute
them? Is there any issue with this approach?


Answer: I would suggest you to use
[workers](https://nodejs.org/api/cluster.html#cluster_worker_process). It will
look something like this:

    
    
    const cluster = require('cluster');
    
    cluster.setupMaster({
        exec: 'fileUploadedByUser.js'
    });
    
    cluster.fork();
    

But I would highly recommend you to review all such files before executing
them, or at least write some code to analyze them and find any system
functions / variables usage.

Also you can use something like [pidusage](https://github.com/soyuka/pidusage)
to track usage of CPU by those files (workers), and if it will reach the limit
you set, just kill the process.

