3

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

2 Answers 2

6
  • 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
Sign up to request clarification or add additional context in comments.

Comments

2

It's impossible to run a Node application without some kind of Node runtime to run it on - therefore, if you wish to distribute your program as a standalone .exe, you will have to bundle Node itself into said executable as well as your code. There are various tools that will do this for you, such as EncloseJS.

5 Comments

Size don't matter, Yes I have to embed node.exe into packaged executable, But how can i? Do you know about babel command line tool? Can you please post working example to package it as single executable?
EncloseJS failed to install on Windows because failed to download resource from https://enclosejs.s3.amazonaws.com/enclose-v0.12.15-win32-5c54091.exe.sha256
@sspsingh: Babel is irrelevant here - it'll compile your JavaScript to work with older versions of the browser/Node, but it has no impact on how you'd package it. That error looks like an issue with your network.
My node.js shell app is just like babel or any other package, which can be used on shell. So i you can try with babel, I will fix it to work with my app, that's why i asked?
@sspsingh: Oh, I see what you mean! There's examples of how to package various existing command line tools in the EncloseJS GitHub - i'd recommend using those as a starting point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.