Nodejs execute exported function from string

I want to know if it is possible to run a function called string in nodejs. All this code works on the server side without visible browser visibility.

Assuming I'm exporting a file test.jswith the following code

module.exports.test = function(x)
{
   console.log(x*5);
}

Can I do it somehow?

main.js

imp = require('test.js');
toExecute = "test";

// somehow call imp.test using toExecute`
+3
source share
1 answer

Of course:

imp[toExecute](5);

Magazines 25.

+7
source

All Articles