Write JavaScript code.

See Code Editors for more information on composing code in WayScript.


WayScript's JS editor lets you reference Variables that exist in your program. To do this, you can reference them through the inputs dictionary.

As an example, let's create a variable called "Location" and set a value of "Brooklyn, NY"

You can reference the Location variable in your JavaScript with this code:

location = inputs[ "Location" ];
// Or, as a JS object
location = inputs.Location;

More abstractly, you reference any variable with the format:

const my_var = inputs[ "<var_name>" ];


Return Data from Your JavaScript

You can also output data from your JS code and turn these into variables that can be used by other Modules in your program.

You can do this with the outputs dictionary in the following format:

outputs[ "<Var Name>" ] = variable;
// example
const currentTime = new Date();
outputs[ "Date" ] = currentTime.toISOString();

Output Raw JavaScript Code

You can output the raw JavaScript code from the code editor by enabling the "JavaScript Code" output. This is useful when building a website using WayScript and inserting JavaScript into HTML.

Raw JS Code Output as a Variable

If you are building JS for a webpage, you might only want to output the code as text and not run it at all. This can be achieved by disabling the "Run Code" setting.

Running JavaScript

While working on your code, you can press the "Run Code" button inside the module to run the JavaScript and see updated results.

Adding Dependencies

If you would like to use an npm module in your code, you can declare those dependencies in the "Dependencies" field.

Declare these dependencies on separate lines, using the format you would for an npm-install command.

You can then consume these packages in your code:

const wayscript = require( 'wayscript' );
wayscript.apiKey = 'YOUR_API_KEY';
let programId = 1234;
wayscript.runProgram( programId );