How to make exe files from a node.js app?

2019-01-01 14:12发布

I have a node app that I wrote, that I run as follows:

node.exe app.js inputArg

Is there some way I can package this into a .exe by itself? So I can just do something like this?

App.exe inputArg

I have some way of faking this by using a batch file, so I can do this:

App.bat inputArg

But this requires that I have all the dependencies and node in that folder, which is not ideal.

17条回答
萌妹纸的霸气范
2楼-- · 2019-01-01 15:06

Bit late on this, but based on the answer, I created a quick "how-to" blog post, using Advanced" Batch To EXE Converter

http://www.alexjamesbrown.com/development/create-a-standalone-exe-to-run-a-node-js-application/

查看更多
春风洒进眼中
3楼-- · 2019-01-01 15:07

Try nexe which creates a single executable out of your node.js apps

https://github.com/nexe/nexe

查看更多
千与千寻千般痛.
4楼-- · 2019-01-01 15:08

I'm recommending you BoxedApp for that. It is a commercial product that working very well. It works for any NodeJS app. The end-user will get just one EXE file for your app. No need for installation.

In Electron, for example, the end user needs to install/uncompress your app, and he will see all the source files of your code.

BoxedApp It is packaging all the files and dependencies that your NodeJS app needs. It supports compressions, and the compiled file works on Windows XP+

When you use it, be sure to add Node.EXE to the compiled app. Choose a node version that supports Windows XP (If you need this)

The program supports command line arguments, So after package, you can do

c:\myApp argument1

And you can get the argument in your node code:

process.argv[1]

Sometimes your app has files dependencies, so in BoxedApp you can add any folder and file as a dependency, for example, you can insert a settings file.

var mySettings=require('fs').readFileSync('./settings.jgon').toString()

More info:

Just a note: usually I'm recommending about open-source/free software, but in this case I didn't found anything that gets the job done.

查看更多
琉璃瓶的回忆
5楼-- · 2019-01-01 15:08

There may be many other options but to my knowledge, there is one project in active development on GitHub https://github.com/zeit/pkg. You can play with it. One more at https://github.com/nexe/nexe but not in active development.

查看更多
骚的不知所云
6楼-- · 2019-01-01 15:10

I've been exploring this topic for some days and here is what I found. Options fall into two categories:

If you want to build a desktop app the best options are:

1- NW.js: lets you call all Node.js modules directly from DOM and enables a new way of writing applications with all Web technologies.

2- Electron: Build cross platform desktop apps with JavaScript, HTML, and CSS

Here is a good comparison between them: NW.js & Electron Compared. I think NW.js is better and it also provides an application to compile JS files. There are also some standalone executable and installer builders like Enigma Virtual Box. They both contain an embedded version of Chrome which is unnecessary for server apps.

if you want to package a server app these are the best options:

node-compiler: Ahead-of-time (AOT) Compiler designed for Node.js, that just works.

Nexe: create a single executable out of your node.js apps

In this category, I believe node-compiler is better which supports dynamic require and native node modules. It's very easy to use and the output starts at 25MB. You can read a full comparison with other solutions in Node Compiler page. I didn't read much about Nexe, but for now, it seems Node Compiler doesn't compile the js file to binary format using V8 snapshot feature but it's planned for version 2. It's also going to have built-in installer builder.

查看更多
登录 后发表回答