RESTApp modules

RESTApps use RequireJS to load and export modules, using the CommonJS module format. Modules are stored in the /module folder.

The following is an example of a module that is required from index.js.

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

   var
      resourceLocatorUtil = require('ResourceLocatorUtil'),
      propertyUtil        = require('PropertyUtil');
   
   // Define this module
   return {
      getSitePageProperty: function(prop) {
         return propertyUtil.getString(resourceLocatorUtil.getSitePage(), prop);
      },

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

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

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