Search code examples
node.jswindowscommandnode-commander

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


Solution

    • 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