May 29th, 2023 × #javascript#node#executables
JavaScript.exe - Standalone Executables
Scott and Wes discuss JavaScript executables - standalone, portable executables containing your Node app, dependencies, and the runtime. They cover use cases, criticisms of large executable sizes, and potential ways to shrink executables.
- JavaScript executables discussion
- What JavaScript executables are
- Use cases for JavaScript executables
- Running JavaScript on non-JS servers
- Reaching Node from other languages
- Criticisms and defense of executable size
- Executable size comparisons to other languages
- Potential for smaller JavaScript executables
- Dino and Bun executables
Transcript
Announcer
Monday. Monday. Monday.
Announcer
Open wide dev fans, get ready to stuff your face with JavaScript, CSS, node modules, barbecue tips, get workflows, breakdancing, soft skill, web development, the hastiest, the craziest, the tastiest TS Webb development treats coming in hot. Here is Wes, Barracuda,
Wes Bos
Boss, and Scott
Scott Tolinski
key.
Scott Tolinski
Welcome to Syntax.
JavaScript executables discussion
Scott Tolinski
On this Monday, hasty treat. We're gonna be talking about JavaScript executables.
Scott Tolinski
We're gonna be executing on some executables talking about dot exe.
Scott Tolinski
Although, executable's not always EXE. That's the that's the Windows extension. So let's talk about what the heck in a JavaScript executable is and why we might need to worry about them and what people are doing about them in the space. We have a bunch of new players, whether that's no Dino bun. A lot of people talking about executable these days. With me as always is my man, Wes Bos. Wes, what's up, my dude? Hey, I am stoked to talk about
What JavaScript executables are
Wes Bos
JavaScript Executables.
Wes Bos
So let's get into what that is real quick, and then we'll get into, like, why would you ever want to do that? So the idea with JavaScript is that JavaScript is not a compiled or or bundled language, meaning that when you Oh.
Scott Tolinski
Like yeah. No. No. It's it's not by default. Yeah. Some languages out there
Wes Bos
will allow you to you write like like Rust is an example.
Wes Bos
You can run it and it will compile it to Go is like this, it will compile it to low level assembly code that will just run on your computer's CPU.
Wes Bos
JavaScript is not that way. You write JavaScript, and then you have to ship that and run that.
Wes Bos
And wherever you're running that, it has to run an environment that has JavaScript. It has to have the entire runtime available to you. So Node recently announced something that they have, Which is being able to create a stand alone executable of your node application. And, essentially, what it does is it takes your entire application, all the dependencies that are necessary, as well as the entire Node. Js runtime packages it up into a tiny, not a tiny a single it's not tiny. We'll talk about that into a single executable that you can then move around and bring with you and run-in anywhere. Not anywhere, but you can run-in places that you have without having to have Node and NPM and all the correct versions and all of these things installed, which is really nice.
Use cases for JavaScript executables
Wes Bos
So this is kind of exciting for JavaScript. Not that most people will need this. However, there are a handful of use cases that you might need something like this. Probably the biggest one is is portability.
Wes Bos
If you want to be able to bring an entire application that runs on Node. Js or bun or Dino or whatever. If you wanna take that and run that somewhere else, it's nice to have it entirely self contained in a single executable Rather than you having to go ahead and say, okay. Well, in order to run this, first, you have to download this folder full of JavaScript files or like a bundled single JS, and then you have to go make sure you go get NPM and make sure you go get the correct version of Node. Js installed. And hopefully you don't have any issues with your employer allowing this X, Y, and Z on your thing. It's just
Scott Tolinski
Extremely not portable.
Wes Bos
Extremely not portable. Yeah. Exactly.
Wes Bos
So I I heard I posted this on Twitter, and there's a couple of people who said, I use this a lot to bring applications onto a user's computer. So he works in IT department.
Wes Bos
They have a lot of people in accounting That need this specific application and the logic for that application runs in Node. Js. So rather than you saying Again, it has to run locally for whatever reason. Right? You can't. It maybe the files are too large or for whatever reason.
Wes Bos
So What he did is he just bundled it into a single executable, and then you could just send that executable to the people that Need to run it, and they can run it on their computer without having to tell them, okay. We'll go go to IT and allow them to npm install X, Y, and Z. It's not going to work. In a lot of cases, it's not going to work.
Wes Bos
Other use cases deploy tooling to servers that are not node servers. So if you think about all of the tools surrounding our ecosystem, A large majority of those tools are built in JavaScript, right? A good example is the Tailwind compiler, right? If you want to be able to run this in a PHP or Rails environment, what do you do? You install PHP and Node on your server and you have to maintain both of those things. What if you're using some sort of service that is Only running in PHP, and you can't install Node. Well, the answer to this is you bundle your entire app into a single executable, and you can run this from literally any programming language that allows you to run a shell process.
Running JavaScript on non-JS servers
Wes Bos
So all programming I did an example with PHP where I visited a website in PHP, and part of the PHP executable was to run this node script.
Reaching Node from other languages
Wes Bos
It does that sort of as a child process, comes back, and then you get the text in PHP and output it in your PHP rendering, right? So that's you being able to reach for other things in other languages from the actual application that yours is built in.
Wes Bos
And the last 1 is just like you could you could run it on a USB stick. I remember I don't know how much popular how popular this is these days, but when I had a computer class in high school, We used to bring all kinds of stuff on USB sticks because you couldn't download or run anything on the school computers, But you could put stuff on USB sticks and launch it. No problem. So if you really wanted to, you could stick your entire
Scott Tolinski
development environment on a USB stick. Just the amount of, like, wrong in that statement that you could just plug in a USB to a a school computer. Mean, I remember doing that too. Even in college, you'd go to the computer lab, and it's it's actually kind of a weird moment to think that USB sticks I've probably long past their peak usage at this point, you know, even though, like, storage on them is probably outrageous now, but I ain't got no need for that. I got the cloud. Yeah. Yeah, exactly.
Wes Bos
I don't know how many times. I used it to hack a Wii a couple of months ago, and then I like, I went to I've had a print stuff. I sometimes still bring a USB in, although emailing it is generally easier.
Scott Tolinski
You know what I use now is I just because I have I have much more storage on SD cards than anything else.
Scott Tolinski
I use an SD card plugged into a u s a USB translator. More than anything nowadays, if I need to install an OTA on my car. I have the best little,
Wes Bos
USB SD reader. It takes mini SD, regular size SD, and it has USB c on one side and USB a on the other side. It's the best because, like, instead of buying a USB stick, I just have millions of SD cards around. Like, my sister is a photographer, So over the years, she's collected lots of 16 gig cards that, like, it's too small to put in a camera anymore. So she gives them to me.
Wes Bos
Sixteen gigs is is plenty. Right? Yeah. I have 1 big 64 one that I just use for everything for my camera. Just try to put note on it. It'll fit. So let's talk about the actual I will it. So, I I tweeted out about this, that node Now can run it into executable. I showed an example of, unfortunately, hello, world. And then I showed the output, and I showed Like, I know. Like, people are going to ask how big this is. So I put the show the size in it. It was 86 megs, and people lost their minds.
Wes Bos
People got so angry. It's probably the most I've ever been, like, harassed on the Internet. Not because, like, people don't like JavaScript, but I turned into the, like, the punching bag for everybody's JavaScript jokes and, like, the stuff people reply to it because, Matt from Caddy tweeted it out, and he's big in the Go community. Right? And, like,
Criticisms and defense of executable size
Scott Tolinski
people who well, oh, man.
Wes Bos
Eighty 6. Hello. Eighty 6 meg. Hello, world. Yeah. And the answer to that is, yes. It's 86 megs because it's 85.999 actual JavaScript runtime because at least for now, JavaScript does not compile into assembly code, and you cannot tree shake.
Wes Bos
People like, why don't you just tree shake it? I'm pretty sure you can't tree shake C plus plus or like rust based stuff That is in Indino.
Wes Bos
So I don't there are ways to to get it smaller. Talk about that in just a second. But the reason why it is so huge, which is 86 megs, which honestly, that's I understand that if people are thinking about, like, it's exhausting that every single Elektron app has its own version of Node, and theoretically, you could ship every node module with its own version of node. But that's not what this is four. This is for what we just talked about earlier. There's these situations where you need a standalone executable. And quite honestly, I don't think that 86 megs is All that big. Like, in the same breath, people the next day, I was asking about Python, and people were telling me to install this, like, Python special package manager.
Wes Bos
And it was 3 and a half gigs. And I was like, you're the same people that were just getting mad at the 86 meg JavaScript run. Quite quite honestly, it's amazing that can have an entire programming environment run-in
Scott Tolinski
that small. Right? It is. And and it's that it is frustrating specifically it. Because people just will ignore the context of every Yeah. Just just as an opportunity to get out of something. Yeah. Just to get a just to get a funny tweet. But in in reality, you know, 8 80 megs is like nothing these days anyways. I'm sorry, folks. We have computers with giant terabytes. Some people just, like, live living like a 1000000000 years ago. You know, it's like it's it's not the same thing, but it's a frustratingly similar type of person to the type of person who, like, won't install a modern version of Windows because LOL, they all suck. When it's like, bro, just the your I I I saw some release about the news windows, and all of the Reddit comments were, like, never installing this. And it's just like, you don't think there's anything in here for updates. You don't think there's anything in here, like, for me? Like, give me all the updates all the time. I I don't care. Just yeah. I'm sorry. Unrelated rant. But, like, 80 megs. Nothing. I know it's a Hello World. That's not the point. Yeah. Totally. I would be mad if I had 80 of these installed in my system, But again, we talked about the benefits and the why of that. That was missed by LOL. Hello, World is whatever. And node modules is so big, which is also why we just did that show on why is Node modules so big. The answer to that is all of that Node modules will not be part of your end application
Executable size comparisons to other languages
Wes Bos
because You can bundle your application. You don't need all that stuff to be included in the bundle. Would you rather have 180
Scott Tolinski
Megabit sized JavaScript executable or 81 megabit.
Scott Tolinski
Megabyte.
Scott Tolinski
So you're gonna get you're gonna get trouble mixing those up. Yeah. I know. Sorry.
Wes Bos
I don't I don't know which one I would like, but I I do know as as, like, a similar if you take a look at other things out there, a compiled like Go app is I asked a couple of people, they're like, Ah, generally, like 2 to 15 megs is like a general Go application. So obviously quite a bit smaller, And that is because those things are compiled to assembly.
Wes Bos
But I also I talked to the folks from Fastly. I wanna get them on the show.
Potential for smaller JavaScript executables
Scott Tolinski
Have you heard of Fastly before? You know, I see it's one of those companies that I've seen their logo so many times. I've seen their website. I've been to their website.
Scott Tolinski
I personally don't have a ton of use for it, but they were one of those logos that pops up everywhere. So I've never really cataloged it in my brain because it always just seemed like somebody else's thing. Honestly, I just thought I've seen their logo all the time, and I'm like, oh, that's, like, some hosting provider from the fastest 5 post or something. Yeah. Yeah. But it's not. It's,
Wes Bos
So it is a hosting provider. But one of the things they have is they have, like, their own Edge environment similar to like a Cloudflare Worker, right? And what they've done is they've taken SpiderMonkey, which is the engine in Firefox, JavaScript engine, and they've made that their runtime. But They compiled it to, Assembly. They are sorry. They compiled it to Wasm, and then they also compile your code to Wasm.
Wes Bos
So I guess it is possible to I'm curious how large that is. They say it can run super fast, but I'm curious, like, maybe we will be able to compile JavaScript to assembly code at some point. Right? It's a thing. Pretty neat.
Scott Tolinski
Yeah. Yeah. That would be a thing. Yeah.
Wes Bos
I I also I went and compiled this without INTL.
Dino and Bun executables
Wes Bos
So, you know, we talk about Intl all the time. You can format money in any currency for any type of viewer. You can format dates for around the world. You can give it a list of milk, eggs, cheese. And you can for North America, we will say milk, eggs and cheese, and and you'll get the commas and the and or the opera. And it'll do that around the world. That package that does internationalization is massive, and it's it's part of most operating systems.
Wes Bos
So on Mac, you don't need that because it's it's built in to to the Mac. However, it's bundling the entire INTL package, which was like 20, 25 megs alone just for the INTL. So if you can You can run Node and say, just give me the North American Intl API. And it it dropped, like, 25 megs off of it. So if you're not formatting currency for Egyptians, then maybe you can do a custom build of this type of thing if you really do care about how big of a size this will be. It feels like if you really care about the size, you should just be writing it, not in JavaScript. Yeah, that's true as well.
Wes Bos
It's not that big of a like maybe if you were running it in, like, a I'm trying to think of, like, a spot where you would run. You care about the size of that, but not about the CPU. You know, like, if it's running on, like, an Arduino or something, You're you're gonna be limited by memory and CPU before you are actual size. Right. Micro SD cards cost nothing. Exactly. Yeah.
Wes Bos
So Dino has this as well. It's called Dino Compile.
Wes Bos
I did the same app, and it was pretty much bang on size with this type of thing.
Wes Bos
They have said that they are going to implement a bunch of flags to bundle without a lot of the stuff so they could they will be working on making it much smaller.
Wes Bos
And then Jared from BUN tweeted out just like yesterday that he is working on it as well. And the Mac OS version of it is only 25 megabytes, so it is getting quite a bit smaller. And I bet we'll see a lot of stuff in this area in the next year or 2. Word.
Wes Bos
That's it. JavaScript Executables.
Wes Bos
Let us know What you would use these types of things for. If you have used them, we'd love to hear it. Tweet us at syntax f dot f m. No. At syntax f m.
Scott Tolinski
It's syntax dot f m on, blue sky. Mhmm. Cool. Well, that's it, and we will catch you on Wednesday. Alright. Peace.
Scott Tolinski
Head on over to syntax.fm for a full archive of all of our shows, And don't forget to subscribe in your podcast player or drop a review if you like this show.