Search This Blog

Thursday, October 1, 2020

javascript to exe : hellow world !

Sometimes you find yourself experiencing familiar waves in strange seas. I'm participating in an AppleSeeds'  frontend course that the state of Israel was kind enough to organize in these corona days.  I am Still in my infancy learning frontend but as the course has reached the stage where learning the ropes of javascript is becoming more and more interesting, I found myself wondering if you can make an executable out of a javascript program. 

And I was surprised and delighted to discover the following stackoverflow discussion how to make exe files from a node.js app and learn that there is more than one way to do so! 

On the one hand, it was saddening to see many solutions being suggested, only to be declared as no longer supported some time later. On the other hand, it was great to learn that there are working solutions both for native node.js apps and for html/css/js. 

I hope to learn and write about the Electron Software Framework in the future. As it was used in the creation of two IDEs (Atom and visual studio code) it is plainly worth looking into for anyone interested in producing executables. 

But for this early stage, I just wanted to see if I can make a "hellow world!" executable, and the NodeJS tool: zeit/pkg seemed ideal for that. 

First, scribbled a tiny javascript program, greeting the world: 

console.log("Hello World!"); 

Which ran smoothly:

C:\...> node 1.js

Hello World

Then, I installed the tool: 

C:...> npm install -g pkg 

(this naturally requires a node-js installation)

Then came the moment to create the executable: 

C:\...>pkg 1.js

> pkg@4.4.9

> Targets not specified. Assuming:

  node12-linux-x64, node12-macos-x64, node12-win-x64

> Fetching base Node.js binaries to PKG_CACHE_PATH

  fetched-v12.18.1-linux-x64   [====================] 100%

  fetched-v12.18.1-win-x64     [====================] 100%

  fetched-v12.18.1-macos-x64   [====================] 100%

And three files were created: 

01/10/2020  05:03 PM        46,297,788 1-linux

01/10/2020  05:03 PM        46,412,420 1-macos

01/10/2020  05:03 PM        42,124,725 1-win.exe


And indeed, the windows exe ran smoothly: 

C:\...>1-win.exe

Hello World


It isn't much, I know, but considering the path I've made since those early years as an Information Systems programmer, DB & System Person, and the recent years in content writing and blogging, is it a wonder that I am happy about being able to create independent programs ?

Today, "hello world"... 

tomorrow ? 

(: 



No comments:

Post a Comment