DEV Community

Cover image for 📦 Bundle Node.js code into single executable binary

📦 Bundle Node.js code into single executable binary

Muhammad Bin Zafar on August 20, 2022

Node.js 🐢, the asynchronous event-driven JavaScript runtime, has unparalleled support for file-system access, among other things - opening up the d...
Collapse
 
mhm13dev profile image
Mubashir Hassan •

Interesting. Thanks for sharing

Collapse
 
midnqp profile image
Muhammad Bin Zafar •

Thanks @mhm13dev! I'm happy to know!

Collapse
 
raguay profile image
Richard Guay •

I’ve ended up using caxa. Pkg didn’t work for my setup.

Collapse
 
pandi1331 profile image
Pandiyan •

Is this works for macos?

Collapse
 
raguay profile image
Richard Guay •

Yes. I use it on a MacBook Pro M1 system

Collapse
 
bias profile image
Tobias Nickel •

hmm, I always did not like that pkg only understand require statements, I never thought of using a compiler such as esbuild first.

Collapse
 
midnqp profile image
Muhammad Bin Zafar • • Edited

@bias Another option would be to use TypeScript, and output CJS.

Collapse
 
othimar profile image
Pélé Oussoumanou •

I tried it with a simple example. It works. Really good. Thanks!👍

Collapse
 
midnqp profile image
Muhammad Bin Zafar •

That's fabulous 🎉 @othimar ! Wish you the best on your journey!

Collapse
 
tobecci profile image
Tochukwu Ojinaka •

did not know this, thanks so much

Collapse
 
midnqp profile image
Muhammad Bin Zafar •

🚀 @tobecci You're always welcome!

Collapse
 
chupzzz profile image
Ruslan ZH •

Great idea to use Esbuild before Pkg! Because when I used Pkg straight to my project JS-file I always had issues with path and includes. Now it works from the first try! Thanks for suggestion.

Collapse
 
darkterminal profile image
Imam Ali Mustofa •

I love you dude!!!! This is really help me...