WebApp modules

WebApps use the CommonJS module format to load and export modules. Modules are stored in sub folders of the /module folder. The sub folders are /server, /common and /client, which represent a context the module should be loaded in.

  • module/
    • server/
      • JavaScript modules that will be executed server side. SiteVision's Public API may be used here, but not objects bound to the browser context.
    • client/
      • JavaScript modules that are used client side.
    • common/
      • JavaScript modules that are used both client and server side.

In the following examples modules are defined by returning a value. Note that the exports and module arguments are excluded.

// /module/server/myModule.js
define(function(require) {
   'use strict';

      portletContextUtil = require('PortletContextUtil'),
      properties         = require('Properties');
   // Define this module
   return {
      getPropertyFromCurrentPage: function(prop) {
         return properties.get(portletContextUtil.getCurrentPage(), prop);

      add: function(a, b) {
         return a + b;
// index.js
(function() {
   'use strict';

      router   = require('router'),
      myModule = require('/module/server/myModule');

   router.get('/', function(req, res) {
      var data = {
         displayName: myModule.getPropertyFromCurrentPage('displayName'),
         result: myModule.add(1, 2)
      return res.render('/', data);