Skip to content
forked from metarhia/metavm

Metarhia script loader, node.js vm wrapper

License

Notifications You must be signed in to change notification settings

a-mountain/metavm

 
 

Repository files navigation

Metarhia script loader, node.js vm wrapper

ci status snyk npm version npm downloads/month npm downloads license

Create script from string

Script contains object expression. You can use it for configs, network packets, serialization format, etc.

const metavm = require('metavm');

const src = `({ field: 'value' });`;
const ms = metavm.createScript('Example', src);
console.log(ms);

// Output:
//   MetaScript {
//     name: 'Example',
//     script: Script {},
//     context: {},
//     exports: { field: 'value' }
//   }

Script contains function expression. You can use it for api endpoints, domain logic stored in files or database, etc.

const metavm = require('metavm');

const src = `(a, b) => a + b;`;
const ms = metavm.createScript('Example', src);
console.log(ms);

// Output:
//   MetaScript {
//     name: 'Example',
//     script: Script {},
//     context: {},
//     exports: [Function]
//   }

Read script from file

const metavm = require('.');

(async () => {
  const ms = await metavm.readScript('./test/examples/simple.js');
  console.log(ms);
})();

// Output:
//   MetaScript {
//     name: 'simple',
//     script: Script {},
//     context: {},
//     exports: { field: 'value', add: [Function: add], sub: [Function: sub] }
//   }

License & Contributors

Copyright (c) 2020-2022 Metarhia contributors. Metavm is MIT licensed.
Metavm is a part of Metarhia technology stack.

About

Metarhia script loader, node.js vm wrapper

Resources

License

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • JavaScript 100.0%