Nodejs execute exported function from string

javascript, node.js

Solution

Sure:

imp[toExecute](5);

Logs `25`.

Problem

I want to know if it's possible to run a function that is named a string in nodejs. All this code is running on the server side with no browser appearance at all. Assuming I export a file `test.js` with the following code ``` module.exports.test = function(x) { console.log(x*5); } ``` Can I do this somehow? main.js ``` imp = require('test.js'); toExecute = "test"; // somehow call imp.test using toExecute` ```

Original source