require module from string
$ npm install --save-dev require-module-from-string $ yarn add -D require-module-from-string
var requireFromString = require('build-module');
const result = requireFromString('module.exports = 3'); // 1
requireFromString(code[, filename])
code Required
Type: string
Desc: Module code.
filenameOptional
Type: string
Desc: absolute file name.
Default: ''
If file provide,it will simple return require(filename)
otherwise, module.exports
which in the code will be returned.
License MIT © dry