node package manager
We need your input. Help make JavaScript better: Take the 2017 JavaScript Ecosystem survey »



simple-browser-require is a simple, node.js-like require() for the browser. It is not an asynchronous script loader.


Wrapping each module in a require.register call:

require.register('my/module/id', function(module, exports, require) {
    // module code here 

...allows the require function to return the module's public contents:

var lib = require('my/module/id'); by decorating the exports object:

var myModuleVar = 'my module';
exports.myModuleMethod = function() {
  return myModuleVar;

...or overwritting the exports object completely:

function MyModule() {
  this.myVar = 'my instance var';
MyModule.prototype.myMethod = function() {
  return this.myVar;
module.exports = MyModule;

Each module is supplied with a require function that resolves relative module ids:

var lib = require('./my/lib'); // in current package 
var SomeClass = require('../someclass'); // in parent package 
var util = require('utils/util'); // from root package