Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

auto-load

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

auto-load

Require all files in subfolders

  • 3.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

auto-load

Build Status Dependency Status Coverage Status NPM version

require() all files in subfolder.

This will pre-load all files with require, and build an object.

For instance, given this tree:

├── 1.js
├── 2.js
├── 3
│   ├── 31.js
│   └── 32
│       └── 321.js
└── with-dash.js

Calling autoload(__dirname) will give:

{
  '1': exportsFromFile,
  '2': exportsFromFile,
  'withDash': exportsFromFile,
  '3': {
    '31': exportsFromFile,
    '32': {
      '321': exportsFromFile
    }
  }
}

Where exportsFromFile is the value returned by the file module.exports.

Non js or json files are not loaded.

You can load the files with two types of paths:

  • Absolute, in which case the files will be included from the full path:
autoload(__dirname);
autoload(__dirname + '/directory')
  • Relative, in which case the files will be loaded relative to the root of your project (where the node instance is being executed). To do this, you simply have to pass the name of the file:
// will load /username/projectname/directory
autoload('directory');

FAQs

Package last updated on 06 Nov 2018

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc