
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
global-define
Advanced tools
AMD loader for Node, it creates global define function to mimic requirejs define in node.
Using amdefine under the hood.
And allows to require modules relative to basePath (escaping ../../../../.. mess).
Combined with support for paths aliases, provides unified environment for modules shared between server and browser (isomorphic javascript).
npm install global-define --save
Include following line within entry point of your application, and it will automatically add global define function to all included modules/files.
index.js:
require('global-define')({basePath: __dirname});
module.js:
// works in node and in a browser
define([
'app/models/property',
'app/collections/property_search'
], function(Property, PropertySearch)
{
// ...
});
Usually its suggested for module id to reflect path to the file, but its not always the case, this is where paths aliases come to help.
In the following example some_module has several components
located within lib folder.
index.js:
require('global-define')(
{
basePath: __dirname,
paths:
{
'some_module/': 'some_module/lib/'
}
});
node_modules/some_module/lib/component.js:
define('some_module/component', [
'some_module/another_component'
], function(Dependency)
{
// ...
});
If certain modules don't play nice with global define on the server, its possible to exclude them from the world of happiness, by adding them to the black list. It supports glob patterns via minimatch module.
Following example will add global define only to the files of the project, without affecting any dependencies.
index.js:
require('global-define')(
{
basePath: __dirname,
blackList: ['node_modules/**']
});
If you want to play safe, you can white list only certain files in the project.
Following example will add global define only to the files in app/shared folder.
index.js:
require('global-define')(
{
basePath: __dirname,
whiteList: ['app/shared/**']
});
By default it creates only global define function, so UMD modules still opt-in for server-side way of doing things (some of them are using UMD not only for loading resources, but to choose between browser/server branches of the code).
If you don't have such modules (or blacklisted them) and you need better requirejs/amdefine support,
set exposeAmdefine to true, to expose .amd and .require properties of the amdefine module
on per file basis.
index.js:
require('global-define')(
{
basePath: __dirname,
blackList: ['node_modules/sinon/'],
exposeAmdefine: true
});
If you want to use global-define within tne entry point of your application (your index file). It returns reference to the define function tailored for the invoking module:
index.js:
var define = require('global-define')({basePath: __dirname});
define(['app/lib/helper'], function(Helper)
{
// ...
});
false)This allows you to pass in a boolean to delete the modules that you are requiring from nodes require.cache array. This is useful in development for making changes without having to restart your node server. Please use with caution, this approach is prone to unforeseen side effects.
index.js
require('global-define')(
{
basePath: __dirname,
deleteModuleCache: true
});
FAQs
Creates global `define` function to provide AMD-style define in node
The npm package global-define receives a total of 1 weekly downloads. As such, global-define popularity was classified as not popular.
We found that global-define 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
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.