Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
enhanced-require
Advanced tools
Enhance the require function in node.js with support for loaders which preprocess files and really async require (AMD). Enables Hot Code Replacement.
More features for node.js require.
require.ensure
require
, define
(from require.js)require.context
Asynchron require functions are really async. They do not use the sync node.js require, but use a async resolving and async readFile.
var myRequire = require("enhanced-require")(module, {
// options
recursive: true // enable for all modules recursivly
// This replaces the original require function in loaded modules
});
// startup your application
myRequire("./startup");
Than you can use them:
// use loaders
var fileContent = require("raw!"+__filename);
// use loaders automatically
var template = require("./my-template.jade");
var html = template({content: fileContent});
// use require.context
var directoryRequire = require.context("raw!./subdir");
var txtFile = directoryRequire("./aFile.txt");
// use require.ensure
require.ensure(["./someFile.js"], function(require) {
var someFile = require("./someFile.js");
});
// use AMD define
require.define(["./aDep"], function(aDep) {
aDep.run();
});
// use AMD require
require(["./bDep"], function(bDep) {
bDep.doSomething();
});
require("enhanced-require")(module, {
recursive: true, // enable for all modules
hot: true, // enable hot code replacement
watch: true // watch for changes
})("./startup");
For hot code reloading you need to follow the hot code reloading spec.
var er = require("enhanced-require");
it("should read the config option", function(done) {
var subject = er(module, {
recursive: true,
substitutions: {
// specify the exports of a module directly
"../lib/config.json": {
"test-option": { value: 1234 }
}
},
substitutionFactories: {
// specify lazy generated exports of a module
"../lib/otherConfig.json": function(require) {
// export the same object as "config.json"
return require("../lib/config.json");
}
}
})("../lib/subject");
var result = subject.getConfigOption("test-option");
should.exist(result);
result.should.be.eql({ value: 1234 });
});
{
recursive: false,
// replace require function in required modules with enhanced require method
resolve: {
// ...
// see enhanced-resolve
// https://github.com/webpack/enhanced-resolve
},
substitutions: {},
substitutionFactories: {},
// See above
// Replace modules with mocks
// keys are resolved and have to exist
amd: {},
// The require.amd object
enhanced: {},
// The require.enhanced object
loader: {},
// additional stuff in the loaderContext
hot: false,
// enable hot code replacement
watch: false,
// Watch for file changes and issue hot replacement
watchDelay: 400,
// Time to summarize changes for watching
}
Copyright (c) 2012 Tobias Koppers
FAQs
Enhance the require function in node.js with support for loaders which preprocess files and really async require (AMD). Enables Hot Code Replacement.
The npm package enhanced-require receives a total of 0 weekly downloads. As such, enhanced-require popularity was classified as not popular.
We found that enhanced-require 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
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.