Getting started

Noder supports CommonJS Modules/1.0, as specified here. This basically allows a module to export its API through exports and to use the exported API from other modules through a synchronous require function. For information about how to write a module, you can refer to the documentation of node.js.

This page describes how to use Noder to load modules in a web browser.

Including noderJS in the page

Script tag

First of all you need to load noderJS inside your page. The simplest way is to use a direct reference to noder-js.ariatemplates.com, as shown below:

<script type="text/javascript" src="http://noder-js.ariatemplates.com/dist/v1.6.2/noder.dev.js"></script>

Note that noder.dev.js is a development version of noderJS. It is easy to use when debugging, as the code is not minified and the file includes error messages. However, it is not recommended to be used in a production environment, as it is quite big so it is slow to download.

Alternatively, you can use one of the following files:

  • noder.dev.min.js: minified version of noder.dev.js (with error messages)
  • noder.js: not minified, without error messages. In case an error occurs, the following extra files are automatically downloaded to display a readable error message: noderError/error.js, noderError/evalError.js, and noderError/acorn.js.
  • noder.min.js: minified version of noder.js (without error messages). This is the recommended version to use on a production environment, unless you want to create your own custom packaging of noderJS, as described here.

Downloading noderJS

You can use noderJS directly from noder-js.ariatemplates.com. Alternatively, if you want to work with noderJS offline, or if you want to host it on your own server, you can get the full set of files either as a downloadable zip file or through the npm repository.

ZIP file

Download zip (1.6.2)

NPM repository

To install noderJS through npm, you can use the following command:

npm install noder-js@1.6.2

This will install client-side files in node_modules/noder-js/dist/browser, for example: node_modules/noder-js/dist/browser/noder.dev.js.

Loading your first module

When the document is ready, noderJS reads all the script tags whose type attribute is application/x-noder (this is configurable) and considers them as modules to be executed.

For example:

<script type="text/javascript" src="http://noder-js.ariatemplates.com/dist/1.6.2/noder.dev.js"></script>
<script type="application/x-noder">
    // This is executed as a module.
    require('lib/myMainModule').start('myParam1', document.getElementById('myItem'));
</script>

It is also possible to both load noderJS and a specific module with a single line:

<!-- The following script tag loads noderJS and then loads lib/myMainModule -->
<script type="text/javascript" src="http://noder-js.ariatemplates.com/dist/1.6.2/noder.dev.js?lib/myMainModule"></script>

A module loaded this way is considered the main module, available through require.main (as it is done in Node.js), so a module can check if it is the main module with: module === require.main.

A configuration object can be specified inside the script tag to change the behavior of noderJS (check the configuration options for more details about available parameters):

<script type="text/javascript" src="http://noder-js.ariatemplates.com/dist/v1.6.2/noder.dev.js">
{
    varName : 'myNoder' // Name of the global variable exposed by noder, the default is "noder"
}
</script>

You can find below a small hello world example (using Plunker) that shows how to load a module. You can click on the "Code" button to see the different files and on the "Preview" button to run the example. You can also click on the "Edit" button to open an online editor. This will allow you to change the files and try all the features of noderJS.