Running files
The most basic way to run JavaScript with Arc is to pass a file path as an argument:Script mode vs module mode
Arc supports two execution modes:Script mode (.cjs files)
Script mode (.cjs files)
Script mode is the traditional JavaScript execution model where code runs in the global scope. Use In script mode:
.cjs extension for script mode:- All code runs in the global scope
- No
import/exportstatements allowed - Variables declared with
varbecome global properties - Suitable for simple scripts and one-off programs
Module mode (.js and .mjs files)
Module mode (.js and .mjs files)
Module mode follows the ES modules specification. Any file with In module mode:
.js or .mjs extension runs as a module:- Code runs in module scope (not global)
importandexportstatements are supported- Top-level
awaitis allowed - Recommended for most applications
One-liner evaluation with -p flag
You can execute JavaScript expressions directly from the command line using the-p flag:
-p flag is useful for:
- Quick calculations
- Testing Arc features
- Shell scripting
- Debugging snippets
Running the example programs
Arc includes several example programs that demonstrate different features. Here’s how to run them:Basic actor example
Thesimple.js example shows the fundamentals of spawning processes and sending messages:
examples/simple.js
All
.js files in the examples directory run as ES modules by default. To run them in script mode, rename them to .cjs.Output and errors
When you run a JavaScript file:Arc parses the file
The JavaScript code is parsed into an abstract syntax tree (AST). Syntax errors are reported immediately:
Arc compiles to bytecode
The AST is compiled into bytecode instructions for the Arc VM. Compilation errors are caught here:
Command-line interface
Here’s the complete Arc CLI syntax:Arc does not pass command-line arguments to your JavaScript programs yet. This feature is planned for a future release.
What’s next?
Now that you know how to run JavaScript files, explore these guides:Using the REPL
Interactive JavaScript development
Actor programming
Writing concurrent programs