Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
enforce-node-path
Advanced tools
Enforce usage of NODE_PATH environmental variable to make loading application modules in Node.js more consistent.
Please Note: Due to the very limited scope of this module, I do not anticipate needing to make very many changes to it. Expect long stretches of zero updates—that does not mean that the module is outdated.
This simple module enforces usage of the NODE_PATH
environmental variable to make loading application modules (modules that are not in node_modules
) in Node.js more consistent.
The Node.js module loader uses a special environmental variable called NODE_PATH
:
If the
NODE_PATH
environment variable is set to a colon-delimited list of absolute paths, then Node.js will search those paths for modules if they are not found elsewhere.
This means that if you set the NODE_PATH
environmental variable to the root of your application, you can load application files relative to your root directory wherever you are.
Assuming that NODE_PATH
set to /var/www
:
// In /var/www/server/router.js
var routes = require('config/routes.json'); // Looks in /var/www/config/routes.json
Unfortunately, the module loader caches this environmental variable before your app runs, so it's not possible to set process.env.NODE_PATH
after the fact. And as the docs state, relying on this variable can be dangerous because developers may not know that it needs to be set. This module makes that dependency explicit and triggers an error if it's not set.
$ npm install enforce-node-path --save
As close to the top of your app's entry point, add the following code:
var enforceNodePath = require('enforce-node-path');
enforceNodePath(__dirname);
If NODE_PATH
is not set to __dirname
(path.resolve
is used, so they just have to resolve to the same directory), an Error
is thrown.
It is recommended that you set this environmental variable in your npm scripts section so that npm start
just works:
{
"scripts": {
"start": "NODE_PATH=. node index.js",
}
}
FAQs
Enforce usage of NODE_PATH environmental variable to make loading application modules in Node.js more consistent.
We found that enforce-node-path 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.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.