"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
  • Xdqwerty @ Xdqwerty:
    @SylverReZ, the other game where I found newgrounds is new york shark
    +1
  • SylverReZ @ SylverReZ:
    Spoke to Tom Fulp the other day, if he can find his old Newgrounds site content like the mini Flash animations from the 2000's that played on the portal.
  • SylverReZ @ SylverReZ:
    So far no response, but he did say that he'll find them. Wayback Machine doesn't have em.
  • Xdqwerty @ Xdqwerty:
    @SylverReZ, atleast the 1999 versión of pico's school is avaliable (the difference between it, the 2006 versión and the 2016 versión is that the speed of the game depends of the speed of your computer and that it had the og soundtrack)
  • SylverReZ @ SylverReZ:
    @Xdqwerty, Another being Pico VS Bear, the original 1999 version before Jim Henson filed a DMCA takedown.
    +1
  • Xdqwerty @ Xdqwerty:
    The 2006 versión was made when the flash portal was made
  • SylverReZ @ SylverReZ:
    Many people thought it was lost, but was discovered that he hid it on the same page.
  • Xdqwerty @ Xdqwerty:
    @SylverReZ, although the "secrets" system where the game was has been removed. Also pico vs uberkids had a netplay versión that was shutdown, although the swf file has been found
  • SylverReZ @ SylverReZ:
    @Xdqwerty, Nope. There are two download buttons on the same page, where you can download the original under a file called "bear.exe". "bear2.exe", however, is the updated game in a Flash projector. P.s. this was on the archived Pico page from 2000.
  • SylverReZ @ SylverReZ:
    @Xdqwerty, That's been there for a long time, too. People who search for lost media don't look hard enough lmao.
    +1
  • Xdqwerty @ Xdqwerty:
    @SylverReZ, also the pico 2 demos used to be only for the newgrounds patrons but they are on internet archive too (https://archive.org/download/picos_school_2)
    +1
  • Xdqwerty @ Xdqwerty:
    Iirc the demos were removed from newgrounds in 2022
  • Xdqwerty @ Xdqwerty:
    @SylverReZ, or well only the demo with mindchamber's style was on newgrounds
    +1
  • Xdqwerty @ Xdqwerty:
    Fun fact @SylverReZ: iirc one of the goals on the fnf Kickstarter stated that pico 2 would be finished but the Kickstarter didnt get enough money for that goal to be fullfiled
  • SylverReZ @ SylverReZ:
    @Xdqwerty, FNF sucks, their community is toxic as hell.
  • The Real Jdbye @ The Real Jdbye:
    @SylverReZ its a single player game
  • Xdqwerty @ Xdqwerty:
    @The Real Jdbye, Yea but it has a shitton of mods with their own songs and stuff
  • Xdqwerty @ Xdqwerty:
    @The Real Jdbye, and quite a lot of people involved in those mods get cancelled
  • SylverReZ @ SylverReZ:
    Newgrounds wasn't the birth of FNF; rather, it was games where you beat up celebrities and parodies.
    +2
  • a_username_that_is_cool @ a_username_that_is_cool:
    FNF was born from Game Jams
  • a_username_that_is_cool @ a_username_that_is_cool:
    Specifically Ludum Dare 47
  • Xdqwerty @ Xdqwerty:
    @SylverReZ, and Sonic fights a la dragón ball z
    T @ Texasauras: help https://www.youtube.com/watch?v=UUPdNq0qyeA