Examples
The examples/
directory of the 3va repository holds 14 small projects. Each page in this
section walks through one of them: what it does, how to run it, what you
should see, how it works, and what to watch out for.
Everything here was run against 3va 2.9.0 on Linux, non-interactively (no TTY). The output blocks are real output from those runs, with only absolute paths shortened.
git clone https://github.com/OdinoCano/3va
cd 3va/examples/01-hello-world
3va run app.jsIndex
| # | Example | What it shows | Command |
|---|---|---|---|
| 01 | Hello World | The simplest script, zero permissions | 3va run app.js |
| 02 | HTTP Server | Node http + --allow-net | 3va run server.js --allow-net=localhost |
| 03 | File Operations | Scoped --allow-read / --allow-write | 3va run app.js --allow-read=./data.json --allow-write=./data.json |
| 04 | TypeScript | Running .ts with no build step | 3va run math.ts |
| 05 | npm Packages | 3va install + package.json grants | 3va install --allow-net=registry.npmjs.org |
| 06 | Dev Server | On-demand ESM serving + full-page HMR | 3va dev --port 3000 |
| 07 | Test Runner | Jest-compatible tests and snapshots | 3va test |
| 08 | Bundler | Multi-file → one self-contained file | 3va bundle src/index.js -o dist/bundle.js --minify |
| 09 | Process Manager | Background daemon + auto-restart | 3va start server.js --name demo-api |
| 10 | Permissions | Deny-by-default, grant by grant | 3va run demo.js |
| 11 | React Native | Run and test the shared TS logic of an RN app | 3va test |
| 12 | Expo | Expo helpers and tooling scripts | 3va run src/index.ts --allow-read=./src |
| 13 | Tauri | 3va as the frontend toolchain of a Tauri app | 3va dev / 3va bundle / 3va test |
| 14 | Native addon | A real .node addon (bcrypt) through Node-API and --allow-ffi | 3va run app.js --allow-ffi ... |
Suggested order
- 01 hello world → 03 files → 02 HTTP server (the two most common capabilities)
- 04 if you write TypeScript
- 07 tests, 05 dependencies
- 06 develop with HMR, 08 ship a bundle, 09 run it as a daemon
- 10 to understand why everything above needs the flags it needs
- 11 · 12 · 13 if you work with a native app framework
- 14 if a dependency ships a compiled
.nodeaddon
Things that apply to every example
These came up again and again while running the examples, so they are collected here once:
- Importing your own files needs
--allow-read. The entry file is always readable, but every module it imports is a file read. A single-file script (01, 04) needs no flags; a script that imports./todos.tsfails withPermission denied: --allow-read=…/src/todos.ts is requireduntil you pass--allow-read=./src. The same goes forrequire()of packages innode_modules(05). - Denials look different depending on the API. A synchronous
fscall throws (EACCES, or an uncaughtPermission denied: --allow-… is requiredthat exits with code 1).process.envquietly looks empty. An async network call reports anEACCESerrorevent, and if nothing listens for it, the script exits with code 0 (02). In every case, 3va lists what it refused when the run ends, with the flag to add (env vars included, when they are read by name).--trace-denialsshows each refusal as it happens. - No TTY, no prompt. In a terminal, 3va asks before granting a missing
capability. In CI, pipes, or redirected output it denies silently.
"no-prompt": trueinpackage.jsonmakes that behavior explicit. 3va permissions learn <script>runs the script with everything allowed and prints the exact flags it used. Add--writeto merge them intopackage.json. It is the quickest way to find the minimum set.3va permissions suggestonly reads the source and produces broad"."scopes.⚠ Dependencies may be out of dateis printed whenever a folder has apackage.jsonbut no installednode_modules(examples 09 and 13). It is harmless for these examples, which have no dependencies. Example 14 does have one (bcrypt): run3va installfirst.
See Permissions for the full model.