dimanche 30 mai 2021

Get user's input and use it as a Function

I am working on a test case visualizer where the user can run his code and check if it is correct. I'm using Node Js and I'm getting user's code from a text-area. Assuming that this is what I'm getting from the user:

 function add(x,y){
                        return x+y;
                    }

And this is what I'm doing at the backend:

app.post("/main", function(req, res) {
    console.log("hello");
    var x = 1;
    var y = 2;
    req.body.code //missing

})

How can I use this input as a function and run it to get the values?




Aucun commentaire:

Enregistrer un commentaire