"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
60
Trophies
0
Age
35
Website
n8.io
XP
466
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
207
Trophies
0
Age
40
XP
560
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,646
Trophies
3
Location
(REDACTED)
Website
zoey-on-github.github.io
XP
1,934
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
60
Trophies
0
Age
35
Website
n8.io
XP
466
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
60
Trophies
0
Age
35
Website
n8.io
XP
466
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
  • K3Nv2 @ K3Nv2:
    Plus all bios are set up and usually includes at least 128gbs or 64
  • K3Nv2 @ K3Nv2:
    Yeah but if your main goal is just to play n64 and GameCube you can save about $50 and have the portability option
    +1
  • BigOnYa @ BigOnYa:
    True, but on 2 monitors at 4k. Its just want you want really, to each they own.
  • K3Nv2 @ K3Nv2:
    For a kids aspect Anbernic would be the better option they'd probably melt over the price on a good 4k display
    +1
  • BigOnYa @ BigOnYa:
    For that texasroo guy, I'd recommend the Spell and speak as his first system.
    +1
  • K3Nv2 @ K3Nv2:
    So they buy a pi5 kit for about $150 and say a 28" 4k display probably looking around $400 total
  • K3Nv2 @ K3Nv2:
    They'll be getting in the territory of portable Pcs anyway
    +1
  • BigOnYa @ BigOnYa:
    Again you get what you pay for, its like buying a S series for $300 but its only 1440p native, if you want true 4k, gotta get the X model for $500. But yea you right, when moms buying it anyways, you gotta stay cheap.
  • K3Nv2 @ K3Nv2:
    They could use HD out on their TV no real need for a monitor these days tbh the purists will disagree
  • K3Nv2 @ K3Nv2:
    I'm kind of phasing out on the need for wanting all these consoles cool to have but they just become dust build ups
  • BigOnYa @ BigOnYa:
    I here ya there, I have too many myself, and have hard time letting them go, since most of mine I've modded at some point. Anymore I just play Switch on the go, seriesx at home.
  • Xdqwerty @ Xdqwerty:
    ack my throat
  • K3Nv2 @ K3Nv2:
    I need to invest in some storage totes tbh
  • BigOnYa @ BigOnYa:
    Tots?
  • K3Nv2 @ K3Nv2:
    Tootles
  • BigOnYa @ BigOnYa:
    Tootles? Wtf
  • K3Nv2 @ K3Nv2:
    Oh tootles
  • BigOnYa @ BigOnYa:
    Oh totes , lol, like Tupperware storage, I gotcha
  • BigOnYa @ BigOnYa:
    I'm designing my own entertainment cabinet for my man cave, to store all my systems, then I'm also designing a power supply/HDMI switcher so I can switch to whichever system I want, and power it also. Already picked up the cabinet board, but tinkering with my drawings before start
  • BigOnYa @ BigOnYa:
    But yea, I have frogger arcade cabinet that I gutted and put a Pi4 then Pi5 into, but it never gets played much anymore, should sell it. Even when the kids come over, they don't want to play on it, just the xbox. TMNT and Simpson's arcade is still so fun on it, esp w 2 players.
  • K3Nv2 @ K3Nv2:
    Gonna check out the new Garfield looks like garbage
  • BigOnYa @ BigOnYa:
    Can't wait to see the new "stick" that can actually play Ps3 or 360 games. I know they are getting close.
  • BigOnYa @ BigOnYa:
    @Xdqwerty didn't you see the new garfield?
  • K3Nv2 @ K3Nv2:
    Ah it's all animated I was hoping for some live action
    +1
  • Xdqwerty @ Xdqwerty:
    @BigOnYa, yes i did
    Xdqwerty @ Xdqwerty: @BigOnYa, yes i did