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...