Skip to main content

Imports

A node may import a variety of both relative and external code or packages. Largely importing adheres to standard JavaScript/TypeScript rules, but there a few special edge cases one should be aware of depending upon the style of import and what is being imported.

Relative Imports

A relative import refers to any file located within your node development space. A relative import always starts with either ./ or ../. Please note it is not possible to import something below the root of your project.

For example, if given the following tree structure...

./
manifest.yaml
properties.yaml
src/
main.js
node1/MyNode1.js
node2/MyNode2.js

The following imports would work:

From src/main.js:

import Node1 from './node1/MyNode1.js';
import Node2 from './node2/MyNode2.js';

from src/node1/MyNode1.js:

import Node2 from '../node2/MyNode2.js';

from src/node2/MyNode2.js:

import Node1 from '../node1/MyNode1.js';

External Imports

Any NPM package can also be imported using the import JavaScript/TypeScript keyword.

import chartjs from 'chartjs/auto';

When an import occurs, Openexus parses the node code and pulls any NPM package imports out, and loads them.