
How to use the command 'just' (with examples)
- Linux
- December 17, 2024
‘just’ is a V8 JavaScript runtime designed to enable developers to run and build JavaScript applications directly on Linux systems. It offers a lightweight and efficient way to execute JavaScript code, similar to Node.js but with a focus on simplicity and minimalism. With ‘just’, you can perform a range of tasks from starting an interactive shell to building standalone executables for JavaScript applications.
Use case 1: Start a REPL (interactive shell)
Code:
just
Motivation:
The Read-Eval-Print Loop (REPL) is an essential tool for JavaScript developers who want to experiment with code snippets quickly without the overhead of writing an entire script file. It’s particularly useful for testing small sections of code, debugging, or exploring language features interactively.
Explanation:
When you run just with no additional arguments, it launches an interactive shell session. This REPL allows you to write and execute JavaScript commands on-the-fly.
Example output:
> 2 + 2
4
> console.log('Hello, World!')
Hello, World!
undefined
>
Use case 2: Run a JavaScript file
Code:
just path/to/file.js
Motivation:
Running JavaScript files with ‘just’ is crucial for executing larger, pre-written codebases. This use case is common for developers who have a script saved to disk that they wish to execute without entering an interactive shell.
Explanation:
Here, just is followed by the path to the JavaScript file you wish to run. This instructs ‘just’ to execute the code contained within the specified file.
Example output:
Assuming the file.js contains console.log('Hello, File!');:
Hello, File!
Use case 3: Evaluate JavaScript code by passing it as an argument
Code:
just eval "console.log('Evaluating code!')"
Motivation:
Evaluating code directly from the command line is beneficial for quick scripts or one-liners that don’t warrant the creation of a separate script file. It’s a fast way to test concepts or share code snippets.
Explanation:
just eval is used with a string of JavaScript code enclosed in quotes. The eval argument signals to ‘just’ that the subsequent string contains code to be executed directly.
Example output:
Evaluating code!
Use case 4: Initialize a new project in a directory of the same name
Code:
just init project_name
Motivation:
Initializing projects is a frequent necessity when starting new development work. Starting with a consistent project setup helps maintain organization and structure, ensuring that all necessary files and configurations are correctly established from the beginning.
Explanation:
The init command tells ‘just’ to create a new directory named project_name and set up the necessary files to kickstart a new JavaScript project there. This often includes basic directory structures and configuration files tailored for use with ‘just’.
Example output:
Initialized empty Just project in project_name
Use case 5: Build a JavaScript application into an executable
Code:
just build path/to/file.js --static
Motivation:
Packaging JavaScript applications into standalone executables can simplify distribution and deployment by reducing dependencies and ensuring that the runtime environment is bundled. This is particularly useful for deploying applications to environments where ‘just’ or other interpreters aren’t readily available.
Explanation:
The build command compiles the JavaScript file specified in path/to/file.js into a single executable. The --static flag indicates that the resulting binary should be statically linked, embedding all necessary dependencies within the executable itself.
Example output:
Assuming successful compilation:
Compiled static executable: file
Conclusion:
The ‘just’ command provides Linux users with powerful tools for running, evaluating, and compiling JavaScript code. Whether you’re testing snippets in REPL, running scripts from files, or building executables for distribution, ‘just’ offers straightforward commands to streamline your development workflow.

