How to “require” a Node.js module

Similarly (yet not identically) to Node.js, the SyncJS language supports the require keyword. Requiring a module is necessary in order to use any of its exported functions. Module functions cannot be used if the module containing them hasn’t been required first.

For example, this script will fail/crash at runtime:

{
  // Will crash because the underscore module hasn't been "required"
  if (_.contains([1, 2, 3], 3)) {
    Log('Yay!');
  }
}

But this script would compile and run flawlessly:

{
  // Require the minified Underscore.js module
  var _ = require("underscore-min");
  // Let's use the "contains" function from the previously required Underscore.js module
  if (_.contains([1, 2, 3], 3)) {
    Log('Yay!');
  }
}

In order to require modules, they have to be installed in the “modules” subdirectory of AFT!’s configuration folder. Typically this folder is located:

  • In Windows: C:\ProgramData\Syncplify.me\AFTv1\modules

  • In Linux (and other Posix OSs): /etc/Syncplify.me/AFTv1/modules

Attention

AFT! does not use nor integrate Node.js; although we try our best to ensure compatibility with Node.js modules, we cannot guarantee that all Node.js modules will work in the AFT! runtime environment.