RESTApp modules
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'),
properties = require('Properties');
// Define this module
return {
getSitePageProperty: function(prop) {
return properties.get(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);
});
}());
Did you find the content on this page useful?