nx.js

Getting Started

Bootstraping your nx.js app

Important

This guide assumes that you have a homebrew enabled Switch. If you don't, you can follow the NH Switch Guide to get started.

Node.js must also be installed on your development machine, in order to run the tooling described in this guide.

To get started on creating your nx.js application, it is recommended that you start with one of the templates and modify the source code from there.

Each template is configured with:

  • TypeScript types properly configured for your code editor
  • A build script which utilizes esbuild to bundle the application into a single file
  • A nro script to package your application into a standalone .nro file (which can be launched from the Switch Homebrew menu)
  • A nsp script to package your application into a standalone .nsp file (which can be installed to and launched from the homescreen)

Clone a template

Create a new nx.js application by running the create-nxjs-app tool:

npx create-nxjs-app@latest
pnpm create nxjs-app@latest
yarn create nxjs-app@latest
bun create nxjs-app@latest

You will be prompted with the list of example applications to select from, as well as the name of your application and a few other personalization options.

In the end, you will have a new directory which contains the cloned template for you to begin tinkering with.

Bundle the source code

The example templates are pre-configured to bundle your application into a single romfs/main.js file (the entrypoint that nx.js runs) using esbuild. This is the recommended workflow: the bundler resolves your imports and npm dependencies at build time, and outputs a single optimized file.

Run the build script to produce romfs/main.js:

npm run build

You can use a different bundler if you prefer, such as Parcel or Rollup.

Note

nx.js also supports native ES module import at runtime, so you can ship an unbundled multi-file app or lazy-load modules with dynamic import(). Bundling is still recommended for distribution, since runtime import resolution is synchronous and limited to local files (romfs:/sdmc:/nxjs: — no bare npm specifiers or remote URLs).

Tip

You may place other files within the romfs directory, and they will become embedded within the RomFS filesystem in the final executable. This is useful for assets such as images, fonts, and other data files. You can read files from the RomFS partition by using the romfs:/ URL protocol.

Package the executable

Now that the romfs directory is populated with the main app bundle (and possibly other assets), you can package the application into a standalone .nro file (which can be launched from the Switch Homebrew menu).

npm run nro

This will result in a <your app name>.nro file in the root directory of your project. You can then upload this file to Switch via FTP or directly copy it to the SD card, and then launch the app from the homebrew menu.

Note

By default this produces a slim NRO — a tiny launcher that shares one nx.js runtime installed on the SD card. See Packaging for the slim vs. fat tradeoff and how the shared runtime is installed.

Learn more

On this page