Skip to content

`jstime run`

The jstime CLI can be used to execute JavaScript/TypeScript files, package.json scripts, and executable packages.

Compare to node <file>

Use jstime run to execute a source file.

Terminal window
$ jstime run index.js

JSTime supports TypeScript and JSX out of the box. Every file is transpiled on the fly by JSTime’s fast native transpiler before being executed.

Terminal window
$ jstime run index.js
$ jstime run index.jsx
$ jstime run index.ts
$ jstime run index.tsx

The “naked” jstime command is equivalent to jstime run.

Terminal window
$ jstime index.tsx

To run a file in watch mode, use the --watch flag.

Terminal window
$ jstime --watch run index.tsx

In memory-constrained environments, use the --smol flag to reduce memory usage at a cost to performance.

Terminal window
$ jstime --smol run index.tsx

Compare to npm run <script> or yarn <script>

Your package.json can define a number of named "scripts" that correspond to shell commands.

{
// ... other fields
"scripts": {
"clean": "rm -rf dist && echo 'Done.'",
"dev": "jstime server.ts"
}
}

Use jstime <script> to execute these scripts.

Terminal window
$ jstime clean
$ rm -rf dist && echo 'Done.'
Cleaning...
Done.

JSTime executes the script command in a subshell. It checks for the following shells in order, using the first one it finds: bash, sh, zsh.

⚡️ The startup time for npm run on Linux is roughly 170ms; with JSTime it is 6ms.

If there is a name conflict between a package.json script and a built-in jstime command (install, dev, upgrade, etc.) JSTime’s built-in command takes precedence. In this case, use the more explicit jstime run command to execute your package script.

Terminal window
$ jstime run dev

To see a list of available scripts, run jstime run without any arguments.

Terminal window
$ jstime run
quickstart scripts:
jstime run clean
rm -rf dist && echo 'Done.'
jstime run dev
jstime server.ts
2 scripts

JSTime respects lifecycle hooks. For instance, jstime run clean will execute preclean and postclean, if defined. If the pre<script> fails, JSTime will not execute the script itself.

JSTime automatically loads environment variables from .env files before running a file, script, or executable. The following files are checked, in order:

  1. .env.local (first)
  2. NODE_ENV === "production" ? .env.production : .env.development
  3. .env

To debug environment variables, run jstime run env to view a list of resolved environment variables.

JSTime is designed to start fast and run fast.

Under the hood JSTime uses the JavaScriptCore engine, which is developed by Apple for Safari. In most cases, the startup and running performance is faster than V8, the engine used by Node.js and Chromium-based browsers. Its transpiler and runtime are written in Zig, a modern, high-performance language. On Linux, this translates into startup times 4x faster than Node.js.

JSTime vs Node.js vs Deno running Hello World

JSTime vs Node.js vs Deno running Hello World