npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vm-nodejs

v0.3.0

Published

Fully emulate your NodeJS runtime inside a NodeJS VM

Downloads

98

Readme

This is a small JavaScript library which attempts to emulate the NodeJS runtime on a V8 VM. It tries to to be as fully compatible with the NodeJS API as possible, while allowing select features to be hooked into. For now, the hooks are limited to the require()-procedure.

:mag: Found an inconsistency with the official NodeJS API that makes some module not work with this VM? Please report it as soon as possible in the issue tracker!

Why

vm-nodejs is different from vm2 in the sense that it does not attempt to provide full isolation, and because of this it is much more lightweight. Above that, it allows hooking into the NodeJS internals in a way that vm2 does not allow.

  • Run multiple programs in one process that share the same dependencies in environments with limited memory
  • Detect when a script was required and reload dependencies (watch-require)

:warning: This library is not meant at all to provide complete isolation, merely a way to run multiple NodeJS instances in one process. If you need complete isolation, see the vm2 package.

Installation

$ npm i --save vm-nodejs

API

const NodeVM = require('vm-nodejs')

module.reload()

Reloads the module and all of its dependencies and returns a fresh Module object as if require() had been called for the first time on the module itself and its dependencies.

module.children

The module objects required by this one.

module.exports

The module.exports object is created by the Module system. Sometimes this is not acceptable; many want their module to be an instance of some class. To do this, assign the desired export object to module.exports. Note that assigning the desired object to exports will simply rebind the local exports variable, which is probably not what is desired.

module.filename

The fully resolved filename to the module.

module.id

The identifier for the module. Typically this is the fully resolved filename.

module.parent

The module that first required this one.

module.require(id)

Provides a way to load a module as if require() was called from the original module.

new NodeVM([options])

Create a new NodeJS virtual machine. Currently takes no options.

nodevm.getModule(modulePath)

Acts in much the same way as require()-procedure, except that paths are resolved relative to the current working directory and it returns a reference to the Module object instead of its exports.

nodevm.on('require', cb)

Will trigger cb each time a new require statement is executed within the context of the NodeJS VM. The callback is triggered with a single argument e which contains the following properties:

  • module: a module instance that represents the module being required
const NodeVM = require('vm-nodejs')

const node = new NodeVM()

node.on('require', e => {
  console.log(`Required ${e.module.filename}`)
})

node.getModule('index.js')

License

The MIT License

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.