Skip to content

Getting Started

You can write and run NX without installing anything, then call it from your own application through a published package, using only the package manager you already have.

Open the playground, pick an example, and edit it. It compiles as you type, in your browser, and reports errors against your source.

Here is a small NX program to paste in. It declares a record type, a component that takes one, and ends with the element that is the program’s result:

type User = { name:string }
let <Greeting user:User /> =
<p>Hello, {user.name}!</p>
<Greeting user=<User name="Ada" /> />

It evaluates to a p element whose content is "Hello, ", "Ada" and "!".

The NX extension for VS Code highlights NX files, reports errors as you type, and adds hover and completion. Install NX Language (Official) from the Visual Studio Marketplace or, for VSCodium, Cursor and other editors built on VS Code, Open VSX. You can also search for nx-lang.nx-language in the Extensions view, or run:

Terminal window
code --install-extension nx-lang.nx-language

It runs on Linux x64, macOS arm64 and Windows x64, and opens any .nx file.

The NxLang.Sdk package compiles and evaluates NX from any .NET 10 application, on Linux x64, macOS arm64 and Windows x64:

Terminal window
dotnet add package NxLang.Sdk
using System.Text.Json;
using NxLang.Nx;
string source = """
type User = { name:string }
let <Greeting user:User /> = <p>Hello, {user.name}!</p>
<Greeting user=<User name="Ada" /> />
""";
JsonElement value = NxRuntime.EvaluateJson(source);
Console.WriteLine(value); // {"$type":"p","content":["Hello, ","Ada","!"]}

NxRuntime.Evaluate<T> deserializes the result into your own type instead, and NxProgramArtifact builds a program once to evaluate it many times.

In a browser or under Node, @nx-lang/sdk-wasm compiles NX to NX IR, and @nx-lang/ir-runtime evaluates that IR:

Terminal window
npm install @nx-lang/sdk-wasm @nx-lang/ir-runtime
import { createNxHost, loadNxModule } from "@nx-lang/sdk-wasm";
import { evaluateFunction, prepareNxIrProgram } from "@nx-lang/ir-runtime";
const host = createNxHost(await loadNxModule());
const artifact = host.buildProgramArtifact(`
type User = { name:string }
let <Greeting user:User /> = <p>Hello, {user.name}!</p>
<Greeting user=<User name="Ada" /> />
`);
const [{ bytes }] = artifact.generateNxIr();
artifact.dispose();
const program = prepareNxIrProgram(bytes);
console.log(evaluateFunction(program, "root"));
// { $type: "p", content: ["Hello, ", "Ada", "!"] }

loadNxModule reads the compiler from disk under Node. In a browser, compile it from its URL with compileNxModule(fetch(url)). An application that only runs NX it compiled ahead of time ships the IR bytes and needs only @nx-lang/ir-runtime.

To build NX from source, use the nxlang command-line tool, or work on NX itself, see Contributing.