"nx.js" - JavaScript runtime for Nintendo Switch homebrew applications

Hello all, I'm feeling like it's time to share the nights / weekends project that I've been working on for the past few months: nx.js

logo.png

nx.js is runtime which enables Nintendo Switch homebrew applications to be written in JavaScript (or anything that compiles to JavaScript, but specifically TypeScript). The idea stems from the desire to port some existing web-based games written in JavaScript over to Nintendo Switch. nx.js focuses on implementing web-based standards that would be useful for a homebrew application, such as the web Canvas API for drawing to the screen, and fetch() for interacting with HTTP servers. Access to the Switch-specific hardware is implemented via the global Switch object, like handling controller and touchscreen inputs, vibrating the controller, and reading / writing files to the SD card. I think it could also be useful for anyone who is interested in creating a homebrew application, but might be intimidated by writing the C code and tooling necessary to get it working.

I was able to port the popular 2048 game, which is a web-based JavaScript game, to be a Switch homebrew app and I'm pretty happy with the result so far. It still needs some polish on the rendering, but the core game mechanics work great without any modification to the original game engine code:


Download "2048.nro" file


Another fun example is rendering the classic Star Wars ASCII text to the screen, by connecting to a telnet server which streams the data over the network:


Download "starwars.nro" file


If you'd like to play around on your own, then there's a bootstrapping utility to get you started. You can pick from one of the example applications and then modify from there. First, make sure you have Node.js installed for the tooling, and then run the following command in your terminal:

Bash:
npm create nxjs-app@latest

create-nxjs-app.png


The example applications are configured to compile the code using esbuild. Applications can then be packaged up into a self-contained NRO file, including custom icon image, title, author, version, and RomFS filesystem for additional assets required for the application (images, custom fonts, etc.) using the nxjs-pack command.

Anyways, nx.js is still in the early development phase from my point of view, but I think it's reached a point where I wanted to get it out there and start getting feedback. It's been fun for me to develop so far and learn some of the in-and-outs of developing Switch homebrew applications, and my hope is that some of the more tricky / nuanced parts can be abstracted out into intuitive and fun / familiar to use APIs for JavaScript apps to utilize going forward.

Let me know what you think! If you would like to get involved in the development of the runtime, or would like help in developing an application using nx.js, come join the Discord server and say hi.

Cheers! 🍻
 
Last edited by tootallnate,

tootallnate

Developer
OP
Developer
Joined
Mar 31, 2023
Messages
58
Trophies
0
Age
35
Website
n8.io
XP
457
Country
United States
this is awesome. do you plan on updating the UI in the future of your homebrew so that games developed using this script are launched inside this app or once installed will people have additional capabilities when creating their own .nsp or folder installs?

I'm not sure if I fully understand your question, but the base nxjs.nro file (which contains the core runtime) is not meant to be used directly (for distribution, at least).

Instead, you invoke the nxjs-pack command which repackages that base nro file to include your app's JavaScript code and any other additional assets (any files located in the romfs directory in your project) into the RomFS section of the nro. It also pulls app name, version, and author information from the package.json file, and will inject the app icon image when a icon.jpg file exists.

nxjs-pack is implemented fully in JavaScript as well, so no C compiler is necessary at all!
 
Last edited by tootallnate,

AndorfRequissa

Well-Known Member
Member
Joined
Sep 8, 2019
Messages
188
Trophies
0
Age
40
XP
509
Country
United States
I'm not sure if I fully understand your question, but the base nxjs.nro file (which contains the core runtime) is not meant to be used directly.

Instead, you invoke the nxjs-pack command which repackages that base nro file to include your app's JavaScript code and any other additional assets (any files located in the romfs direcrtory in your project) into the RomFS section of the nro. It also pulls app name, version and author information from the package.json file, and will also inject the app icon image when a icon.jpg file exists.

nxjs-pack is implemented fully in JavaScript as well, so no C compiler is necessary at all!
thanks that answered my questioned.
 
  • Like
Reactions: tootallnate

Julie_Pilgrim

Secretly three raccoons in a trench coat
Member
Joined
Sep 2, 2020
Messages
2,645
Trophies
3
Location
(REDACTED)
Website
zoey-on-github.github.io
XP
1,886
Country
United States
Could this lead to Minecraft java on the switch? I bet with mods it could run 100x better than Bedrock native
No. java and javascript are very different
a good way to explain it is this quote
"java is to javascript what car is to carpet"
 

tootallnate

Developer
OP
Developer
Joined
Mar 31, 2023
Messages
58
Trophies
0
Age
35
Website
n8.io
XP
457
Country
United States
A browser then.

nx.js is not quite a browser. It's more similar to a runtime like Node.js. There is no HTML / CSS / layout engine. It's just JavaScript, a Canvas to draw onto the screen, and a global `Switch` object with access to the Switch native APIs.

The Switch OS does include a built-in web browser though, which is accessible through homebrew apps. I would like to expose this functionality in nx.js, just need to figure out what the API should look like.
 

tootallnate

Developer
OP
Developer
Joined
Mar 31, 2023
Messages
58
Trophies
0
Age
35
Website
n8.io
XP
457
Country
United States
This is perhaps a bit silly, but.. Can it use the bluetooth on the console to find and connect to things? Namely asking this because of SpheroV2.js. It'd be fun to make something that could control a Sphero from the switch, or vice versa.

Interesting idea! It looks like libnx does expose Bluetooth related APIs (btdrv), but at the moment none are exposed within nx.js. Feel free to open a GitHub issue to track as a feature request.
Post automatically merged:

nx.js v0.0.18 has been released!

This version includes the initial implementation of the WebAssembly interface, which should open the door for running all kinds of neat stuff that's been compiled to WASM. I'm planning on getting demos up for physics engines (box2d, bullet), layout engines (yoga), source maps (for fixing source maps while debugging stack traces), etc.

Let me know if you get any cool WASM binary working, or open a GitHub issue with details if anything isn't working correctly. Cheers! 🍻
 
Last edited by tootallnate,

brenohd

New Member
Newbie
Joined
Feb 27, 2024
Messages
2
Trophies
0
Age
28
XP
16
Country
Brazil
The Switch OS does include a built-in web browser though, which is accessible through homebrew apps. I would like to expose this functionality in nx.js, just need to figure out what the API should look like.
Really would like to try this when you figure it out. What I want to run is a GeForce Now, Luna and xCloud, but it probably would need something to manipulate browser's user-agent, as they require specific browsers.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    S @ salazarcosplay: @BakerMan can one play cod from hen ps3?