Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
A simple autoloader for node modules.
Local:
npm install modload --save
Global:
npm install modload -g
Require all files in a given directory and store the results in an array:
const load = require('modload')
const plugins = load.asArray({
dir: path.join(__dirname, 'plugins')
})
server.register(plugins, (err) => {
if (err) throw new Error(err)
})
Require all files in a given directory and store the results in an object whose structure matches the directory structure:
const load = require('modload')
const app = load.asObject({
dir: path.join(__dirname, 'app')
})
If the directory structure looks like:
./
|- app
|- |- routes
|- |- |- home.js
|- |- |- login.js
|- |- plugins
|- |- |- auth.js
Then the resulting object will match this structure:
const app = {
routes: {
home: require('./app/routes/home.js'),
login: require('./app/routes/login.js')
},
plugins: {
auth: require('./app/routes/auth.js')
}
}
This object can be attached to the global
object via an optional argument.
Modload provides two methods, which both take an options object to configure their behaviour.
asArray(options)
Array of required modules.
Options object with the following fields:
dir
( String | required )
Root directory of files to require
include
( Array of RegExp | default: null )
RegExp patterns of files to include. Patterns are combined into a single regex pattern with OR. Exclude patterns take precedence over include patterns.
exclude
( Array of RegExp | default: null )
RegExp patterns of files to exclude. Patterns are combined into a single regex pattern with OR. Exclude patterns take precedence over include patterns.
stopfile
( String or RegExp | default: null )
A file in the directory tree matching this pattern is interpreted as the entry point for it's parent directory. Only this file is required; all other files in the same directory, and in sub-directories, are skipped.
es6modules
( Boolean | default:
false
)A flag to specify whether modules are exported with ES6 module syntax (i.e. using the
export
keyword). Iftrue
, modload will require the default value (i.e., whatever is exported byexport default
)
modules
( Array of Strings | default:
null
)Array of module names to load. Useful for loading third-party modules at the same time as your own modules. Loaded before custom modules. For example
load.asArray({... modules: ['hapi']})
will load thehapi
module before any others specified.
asObject(options)
Object of module objects, structured to reflect directory structure.
Options object with exactly the same fields as for the asArray
method, but with the following additional fields:
isglobal
( Boolean | default: false )
If true, the returned object will also be attached to the
global
object under the key specified by thenamespace
parameter
namespace
( String | default: 'app' )
Specifies the key of the
global
object to which the object will be attached.
FAQs
A module autoloader
The npm package modload receives a total of 0 weekly downloads. As such, modload popularity was classified as not popular.
We found that modload demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.