The require function in WebApps

The require function is available in both server-side and client-side context of a WebApp. Though, not all objects are available in both contexts.

Client

Below is an example of objects available client-side via the require function. Note that only client and common modules are available.

// Client context
var
  _              = require('underscore'),
  $              = require('jquery'),
  events         = require('events'),
  redux          = require('redux'),
  
  router         = require('router'),
  i18n           = require('i18n'),
  app            = require('app'),
  store          = require('store'),
  requester      = require('requester'),

  Component      = require('Component'),
  ListComponent  = require('ListComponent'),

  MyComponent    = require('/component/NameOfComponent'), 

  myTemplate     = require('/template/nameOfTemplate'),
  
  myClientModule = require('/module/client/nameOfClientModule'),
  myCommonModule = require('/module/common/nameOfCommonModule');

Server

Below is an example of objects available server-side via the require function. Note that only server and common modules are available.

// Server context, e.g. index.js or a server module
var
  _              = require('underscore'),
  
  router         = require('router'),
  i18n           = require('i18n'),
  app            = require('app'),

  appData        = require('appData'),
  appResource    = require('appResource'), // since 4.5.1
  appInfo        = require('appInfo'), // since 4.5.3
  url            = require('url'),

  Component      = require('Component'),
  ListComponent  = require('ListComponent'),

  MyComponent    = require('/component/NameOfComponent'),  

  myTemplate     = require('/template/nameOfTemplate'),
  
  myServerModule = require('/module/server/nameOfServerModule'),
  myCommonModule = require('/module/common/nameOfCommonModule');

The SiteVision Public API is also accessible server-side. All interfaces, classes and enums that are anotated with the @Requireable annotation is available via the require function.

// Server context, e.g. index.js or a server module
var
  properties             = require('Properties'),  // since 4.5.2
  propertyUtil           = require('PropertyUtil'),
  resourceLocatorUtil    = require('ResourceLocatorUtil'),
  portletContextUtil     = require('PortletContextUtil'),
  permissionUtil         = require('PermissionUtil'),
  publishingUtil         = require('PublishingUtil'),
  versionUtil            = require('VersionUtil'),
  metadataUtil           = require('MetadataUtil'),
  metadataDefinitionUtil = require('MetadataDefinitionUtil'),
  outputUtil             = require('OutputUtil'),  
  userIdentityUtil       = require('UserIdentityUtil'),
  mimeTypeUtil           = require('MimeTypeUtil'),
  nodeIteratorUtil       = require('NodeIteratorUtil'),
  nodeTreeUtil           = require('NodeTreeUtil'),  
  nodeComparatorUtil     = require('NodeComparatorUtil'),
  nodeFilterUtil         = require('NodeFilterUtil'),
  nodeTypeUtil           = require('NodeTypeUtil'),
  localInboundRestApi    = require('RestApi'),
  ...