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

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

nx.js evaluates a single JavaScript file at runtime. It does not implement a module loader. Therefore, when separating your application code into multiple files, it is the responsibility of a bundler to combine the source files into a singular "bundle", which is the code that nx.js runs.

All of the example templates are pre-configured to use esbuild, but you can use a different bundler if you prefer, such as Parcel or Rollup.

Run the build script to bundle the application into the romfs/main.js file, which is the entrypoint of the nx.js app:

npm run build
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.

Learn more

On this page