New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

vmod

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vmod

Virtual module for node.js

latest
Source
npmnpm
Version
1.1.5
Version published
Maintainers
1
Created
Source

NPM version Downloads

Virtual module for node.js - vmod

  • Runs in different script context than your current script;
  • Executes a string of code in require-like environment;
  • Allows you to override globals of the sandbox environment;
  • Returns module.exports output;
  • Throws errors that can be caught in your current context;

Known limitations:

  • console.log, console.warn, console.error, etc. output not visible;
  • Modifications to prototypes of some globals not visible in the vmod context;
  • Only CommonJS modules supported;

Installation

$ npm install vmod --save

Simple

const vmod = require('vmod');

console.log(
  vmod('module.exports = 123;')
); // 123

Export function

const vmod = require('vmod');

console.log(
  vmod(
    'module.exports = () => "yay!";'
  )()
); // "yay!"

Require External file

/*
./_test-file.js:
module.exports = "test file data";
*/

const vmod = require('vmod');

console.log(
  vmod(
    'module.exports = require("./_test-file.js")'
  )()
); // "test file data"

Override sandbox variable

const vmod = require('vmod');

vmod(
  'module.exports = require("./_test-file.js")',
  { require: null }
); // TypeError: require is not a function

Keywords

virtual

FAQs

Package last updated on 28 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts