node package manager
Love JavaScript? Your insights can make it even better. Take the 2017 JavaScript Ecosystem Survey »



Build Status

This package provides namespaces for your nodejs or browser app. It help's you organizing your code without writing wired variable constructs and helper objects.


npm install ns

then require the module in your application code

var namespace = require('ns');

or in the browser simply add the namespace.js to your script sources

<script type="text/javascript" src="namespace.js"></script>


Define a new namespace and assign a function

namespace('', function() {
  console.log('Hello World');

now you can run the function in any of your scripts which have access to the same window/global object.

A namespace can contain everything. Objects, functions and even variables - string, integer, float, ...

namespace('')(); // => Hello World 

Where is the namespace stored?

When you assign any kind of variable, object or function to a namespace it won't be stored in the namespace scope. It is attached on nodejs to the global var and in your local browser to window. These variables are reachable for all code in your application.

So you may access the namespace defined as follows:

namespace('', "Hello World");

in this way: // => Hello World // => Hello World 


The project is licensed under the conditions of the MIT licence.