
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Node OR Browser
detect if the script is running on node or in a browser
This library is easy to install by cloning the repo or installing it through npm too:
Local installation
npm install norb
Global installation
npm install -g norb
const norb = require('norb')(module);
//{
// isNode:boolean (true),
// isBrowser:boolean (false),
// export:[Function],
// import:[Function],
// require:[Function]
// }
<script src="norb.js"></script>
isNode [Boolean]: true if running in node
isBrowser [Boolean]: true if running in browser
export export(Object, name?, mode?)
This method allow to export an object in the correct way, independant if the code is in a Node or a Browser environment. (?) In the Browser context you have to assign a name? that will point to window[name] object; the mode? help to decide in which way the object will be overwritten can be 0: ( conserve ) that preserve the original window[name] if present, 1: ( overwrite ) that overwrite anyway, 2: ( merge ) that merge both object.
NB Browser doesn't support system API and Node doesn't support some of the Broswer API
import import(path)
Enclose and import a Browser module, like it would be a Node module.
NB Browser doesn't support system API and Node doesn't support some of the Broswer API
require require(path, [name?, mode?,] callback)
Require a Node module, like it would be a Browser module. In Browser the method is async so you must define a callback for take the module result; with name parameter you can autoassign the module to the window[name]. (?) In the Browser context you have to assign a name? that will point to window[name] object; the mode? help to decide in which way the object will be overwritten can be 0: ( conserve ) that preserve the original window[name] if present, 1: ( overwrite ) that overwrite anyway, 2: ( merge ) that merge both object.
NB Browser doesn't support system API and Node doesn't support some of the Broswer API
File mymodule.js
//Module to be exported
const norb = require('norb')(module);
var export = {};
export.test = function(){console.log('sample function for testing')};
norb.export(export,'myModule');
File index.html (Browser)
...
<script src="./norb.js"></script>
<script>
norb.require('./mymodule.js',(module)=>module.test()); // "sample function for testing"
</script>
...
File node.js (Node)
const norb = require('norb')(module);
const myModule = norb.require('./mymodule');
myModule.test(); // "sample function for testing"
If you like the project feel free to contact me on my .
Something gone wrong? Feel free to rise an issue!
Did you like this project and it was usefull? Help me improve my work:
FAQs
node or browser: detect if the script is running on node or in a browser
We found that norb 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.