As soon as a project scales larger than a Hello, World! program, project structure becomes important. Creating boundaries between components, defining APIs and decoupling unrelated pieces all make for a more cleaner, easier to maintain, design. Tabris.js supports this with npm and the Common.js module system.
Number 8 on my list is the Module System.
Tabris.js uses Common.js to define modules. Typically, modules are defined in their own file. A module defines its exports:
And can depend on other modules through the use the require function.
For more complicated modules, Tabris.js supports module definitions via a package.json. The package.json is the module definition used by npm (the Node Package Manager). A package.json specifies a modules name, version, metadata such as author and license, and the main entry point for the module.
Since Tabris.js uses npm’s standard packaging files, depending on node modules is a breeze. For example, if you need the CRC32 algorithm, simply require it in your app and type npm install crc-32. Or, add it as a dependency in your main package.json and type npm install.
Finally, Tabris.js itself has been packaged as a node module and can be installed with NPM. This allows you to target specific Tabris.js versions and track those dependencies in your own modules.
Special thanks to Tim Buschtöns for the work on the module system in Tabris.js. You can read his excellent blog post for more information.
For more information on Tabris.js, follow us on Twitter.