Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Node.js command line app to single executable?

I built simple command line application using commander.js for Node.js platform. Now I want to compile it to simple exe file, Which I can execute directly.

Means I want single executable file for complete application

This is my application structure

APP_ROOT
  | - package.json
  | - node_modules
  | - node_modules/.bin/myapp.bat
  | - node_modules/myapp/bin/myapp
  | - node_modules/myapp/bin/myapp-action1
  | - node_modules/myapp/bin/myapp-action2

Thanks

like image 750
ssp singh Avatar asked Feb 01 '26 05:02

ssp singh


1 Answers

  • This is, How i packages my node.js command line app to single executable
  • Install pkg module using npm i -g pkg
  • This is my package.json File

json

{
  "name": "my-app-exe",
  "version": "1.0.0",
  "description": "Myapp-Cli tool as executable",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "myapp",
    "cli",
    "exe"
  ],
  "author": "Shisht",
  "license": "MIT",
  "devDependencies": {
    "myapp": "1.0.0"
  },
  "bin": "node_modules/myapp-cli/bin/cli",
  "pkg": {
    "assets": "node_modules/**/*"
  },
  "help": "pkg . --target host --output myapp-1.0.0-x64.exe --debug"
}
  • Command used to package myapp to myapp.exe pkg . --target host --output myapp-1.0.0-x64.exe --debug
like image 133
ssp singh Avatar answered Feb 02 '26 21:02

ssp singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!