Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeVM not working correctly #3

Closed
taylor224 opened this issue Nov 27, 2017 · 2 comments
Closed

NodeVM not working correctly #3

taylor224 opened this issue Nov 27, 2017 · 2 comments

Comments

@taylor224
Copy link

I am expecting the module.get_member() function to get variable from the vm.code() result.
But everytime It returns just None.

from node_vm2 import NodeVM, VMServer, VM

vm_option = {
    'console': 'inherit',
    'sandbox': [
    ],
    'require': {
        'external': [],
        'builtin': [],
        'import': [],
        'root': "./",
        'mock': { }
    }
}

with VMServer() as server:
    with NodeVM(server=server, **vm_option) as vm:
        with vm.code("var abc = 'aa';") as module:
            print(module.get_member('abc'))

print(module.get_member('abc')) just shows None.

@eight04
Copy link
Owner

eight04 commented Nov 27, 2017

In Node.js, variables need to be exported so that they can be accessed from outside of the module. Try changing the JS code to:

var abc = 'aa';
exports.abc = abc;

@taylor224
Copy link
Author

It's working great!
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants