Skip to content

Using Node.js modules

Phil Beauvoir edited this page Feb 18, 2024 · 11 revisions

Using Node.js modules in your jArchi script

Since jArchi 1.6 you can access your own modules or other Node.js modules

A simple example:

  1. In your jArchi scripts folder create a sub-folder named node_modules. This is the parent folder for node modules.
  2. In the node_modules folder create a sub-folder named helloworld. This will be the folder for your module.
  3. In the helloworld folder create a file called index.js containing this code:
exports.sayHelloWorld = function() {
    window.alert("Hello World!");
}
  1. In your jArchi scripts folder create a file called test_module.ajs containing this code:
const speaker = require("helloworld");
speaker.sayHelloWorld();
  1. Run the test_module.ajs script