
Security News
PEP 810 Proposes Explicit Lazy Imports for Python 3.15
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
moduleconfig
Advanced tools
loading configuration files for node modules. If you are building a node module that needs a configuration file, that the user of the module creates, you have come to the right place.
MyModule
with a user config fileThe module MyModule
has a configuration, by convention this configuration specified in in the file config.js
.
Main
the module MyModule
is required.Main
the module ExternalModule
is also required.ExternalModule
also requires MyModule
This means that when the module ExternalModule
uses MyModule
the configuration should be loaded from Main/node_modules/ExternalModule/config.js
,
and when the project Main
uses the module MyModule
the configuration should be loaded from Main/config.js
Because Main
and ExternalModule
both require the same version of MyModule
.
npm
only installs MyModule
in Main/node_modules/MyModule
.
MyModule
is not installed in Main/node_modules/ExternalModule/node_modules/MyModule
.
Therefore the require
-ing MyModule
from the code ExternalModule
in does not load the correct
config. It loads the config from Main/config.js
and not from Main/node_modules/ExternalModule/config.js
as it should.
The Main
projects config overrides the ExternalModule
config.
Use moduleconfig
in the module MyModule
MyModule.js is the main file pointed to by the package.json
in the MyModule
module
var moduleConfig = require("moduleconfig");
module.exports = moduleConfig(["config.js"], function(configFilePath){
return instantiateMyModulefromConfig(require(configFilePath));
});
You will have to implement the instantiateMyModulefromConfig
function yourself.
This will mean that this:
var myModule = require("MyModule");
will return an myModule
based on Main/node_modules/ExternalModule/config.js
when MyModule
is required
from a javascript file anywhere in the path Main/node_modules/ExternalModule/...
and it will return an myModule
based on Main/config.js
when MyModule
is required by code in Main
.
FAQs
configuration loading for node modules
We found that moduleconfig demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 9 open source maintainers 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.
Security News
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.