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
Weekly downloads
28M
increased by1%
Maintainers
1
Install size
4.38 kB
Created
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], [options])

code

Required
Type: string

Module code.

filename

Type: string
Default: ''

Optional filename.

options

Type: object

appendPaths

Type: Array

List of paths, that will be appended to module paths. Useful, when you want to be able require modules from these paths.

prependPaths

Type: Array

Same as appendPaths, but paths will be prepended.

License

MIT © Vsevolod Strukchinsky

FAQs

Last updated on 09 Apr 2018

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