Socket
Socket
Sign inDemoInstall

require-from-string

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

require-from-string

Require module from string


Version published
Maintainers
1
Weekly downloads
27,699,201
decreased by-0.18%
Install size
2.49 kB

Weekly downloads

Package description

What is require-from-string?

The require-from-string npm package allows you to dynamically load modules from a string of code. This can be particularly useful for executing dynamically generated code or loading modules from sources other than the filesystem, such as databases or network responses.

What are require-from-string's main functionalities?

Load module from string

This feature allows you to load a module by passing a string of code to the require-from-string function. The module can then be used as if it were required from a file.

const requireFromString = require('require-from-string');
const code = 'module.exports = { hello: () => "Hello, world!" }';
const module = requireFromString(code);
console.log(module.hello()); // Outputs: Hello, world!

Other packages similar to require-from-string

Readme

Source

require-from-string Build Status

Load module from string in Node.

Install

$ npm install --save require-from-string

Usage

var requireFromString = require('require-from-string');

requireFromString('module.exports = 1');
//=> 1

API

requireFromString(code, [filename])

code

Required
Type: string

Module code.

filename

Type: string

Optional filename.

License

MIT © Vsevolod Strukchinsky

FAQs

Last updated on 06 Nov 2015

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc