简体   繁体   English

如何从 node.js 应用程序制作 exe 文件?

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

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?有什么方法可以让我将 package 单独放入 a.exe 中? 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.但这要求我拥有该文件夹中的所有依赖项和节点,这并不理想。

The solution I've used is Roger Wang's node-webkit .我使用的解决方案是 Roger Wang 的node-webkit

This is a fantastic way to package nodejs apps and distribute them, it even gives you the option to "bundle" the whole app as a single executable.这是打包和分发 nodejs 应用程序的绝佳方式,它甚至让您可以选择将整个应用程序“捆绑”为单个可执行文件。 It supports windows, mac and linux.它支持windows、mac和linux。

Here are some docs on the various options for deploying node-webkit apps, but in a nutshell, you do the following: 以下是有关部署 node-webkit 应用程序的各种选项的一些文档,但简而言之,您可以执行以下操作:

  1. Zip up all your files, with a package.json in the root压缩所有文件,在根目录中包含 package.json
  2. Change the extension from .zip to .nw将扩展名从 .zip 更改为 .nw
  3. copy /b nw.exe+app.nw app.exe复制 /b nw.exe+app.nw app.exe

Just as an added note - I've shipped several production box/install cd applications using this, and it's worked great.就像附加说明一样 - 我已经使用它运送了几个生产盒/安装 cd 应用程序,并且它运行良好。 Same app runs on windows, mac, linux and over the web.同一个应用程序可以在 windows、mac、linux 和网络上运行。

Update: the project name has changed to 'nw.js' and is properly located here: nw.js更新:项目名称已更改为“nw.js”并正确位于此处: nw.js

There a few alternatives, both free and commercial.有一些替代方案,包括免费的和商业的。 I haven't used any of them but in theory they should work:我没有使用过它们中的任何一个,但理论上它们应该可以工作:

Most will require you to keep the batch file as main executable, and then bundle node.exe and your scripts.大多数将要求您将批处理文件保留为主可执行文件,然后捆绑 node.exe 和您的脚本。

Depending on your script, you also have the option to port it to JSDB , which supports an easy way to create executables by simply appending resources to it.根据您的脚本,您还可以选择将其移植到JSDB ,它支持通过简单地向其附加资源来创建可执行文件的简单方法

A third quasi-solution is to keep node somewhere like C:\\utils and add this folder to your PATH environment variable.第三个准解决方案是将 node 保留在C:\\utils类的地方,并将此文件夹添加到您的PATH环境变量中。 Then you can create .bat files in that dir that run node + your preferred scripts - I got coffeescript's coffee working on windows this way.然后你可以在那个运行节点的目录中创建 .bat 文件+你喜欢的脚本——我让coffeescript的coffee以这种方式在windows上工作。 This setup can be automated with a batch file, vb script or installer.可以使用批处理文件、vb 脚本或安装程序自动执行此设置。

For anyone stumbling upon this question, there are now two projects that create exes out of your node projects, Pkg and Electron.atom.io , they differ slightly:对于任何遇到这个问题的人,现在有两个项目可以从您的节点项目中创建 exe, PkgElectron.atom.io ,它们略有不同:

  1. Pkg will compile your project to native code, they also include assets AND a NodeJS installation (the system won't need to install NodeJS to run the executable). Pkg会将您的项目编译为本机代码,它们还包括资产和 NodeJS 安装(系统不需要安装 NodeJS 来运行可执行文件)。 Your source code will not be included.您的源代码将不包括在内。 The resulting executable is Windows ONLY ( .exe ).生成的可执行文件仅适用于 Windows ( .exe )。 All platforms are supported now.现在支持所有平台。 It now requires a licence for commercial products.它现在需要商业产品的许可证。 Fully open source.完全开源。
  2. Electron.atom.io while it will not compact and generate an executable for you, it CAN be used to distribute NodeJS apps since they offer a way to distribute applications . Electron.atom.io虽然它不会压缩并为您生成可执行文件,但它可以用于分发 NodeJS 应用程序,因为它们提供了一种分发应用程序的方法 The benefits are that electron is multi-platform (Windows, macOS, Linux), the cons are that your source code WILL be included, even though they offer a way to distribute your app inside an asar archive.好处是电子是多平台的(Windows、macOS、Linux),缺点是您的源代码将被包含在内,即使它们提供了一种在asar存档中分发您的应用程序的方法 It will not be bulletproof but it's still better than your source in plain.它不会是防弹的,但它仍然比你的源代码更好。

The best tool I know is NodeJS tool: zeit/pkg我所知道的最好的工具是 NodeJS 工具: zeit/pkg

It is very easy to use (much more than Nexe, just as an example), you can just install in globally: npm install -g pkg它非常易于使用(比 Nexe 多得多,仅作为示例),您可以全局npm install -g pkgnpm install -g pkg

to create executables for macOS, Linux and Windows:为 macOS、Linux 和 Windows 创建可执行文件:

pkg exampleApp.js

I had a bit of complicated code which used NodeJS socket server, I tried different applications, none of them created it properly, except zeit/pkg .我有一些使用 NodeJS 套接字服务器的复杂代码,我尝试了不同的应用程序,除了zeit/pkg之外,没有一个正确地创建它。

By default, Windows associates .js files with the Windows Script Host , Microsoft's stand-alone JS runtime engine.默认情况下,Windows 将.js文件与 Microsoft 的独立 JS 运行时引擎Windows Script Host相关联。 If you type script.js at a command prompt (or double-click a .js file in Explorer), the script is executed by wscript.exe .如果您在命令提示符下键入script.js (或在资源管理器中双击.js文件),则该脚本由wscript.exe执行。

This may be solving a local problem with a global setting , but you could associate .js files with node.exe instead, so that typing script.js at a command prompt or double-clicking/dragging items onto scripts will launch them with Node.这可能是通过全局设置解决本地问题,但您可以将.js文件与node.exe 相关联,以便在命令提示符下键入script.js或双击/拖动项目到脚本上,将使用 Node 启动它们。

Of course, if—like me—you've associated .js files with an editor so that double-clicking them opens up your favorite text editor, this suggestion won't do much good.当然,如果——像我一样——你已经将.js文件与一个编辑器相关联,以便双击它们打开你最喜欢的文本编辑器,这个建议不会有多大用处。 You could also add a right-click menu entry of "Execute with Node" to .js files, although this alternative doesn't solve your command-line needs.您还可以.js文件添加“使用节点执行” 的右键单击菜单项,尽管此替代方法不能解决您的命令行需求。


The simplest solution is probably to just use a batch file – you don't have to have a copy of Node in the folder your script resides in. Just reference the Node executable absolutely:最简单的解决方案可能是只使用批处理文件——您不必在脚本所在的文件夹中拥有 Node 的副本。只需绝对引用 Node 可执行文件:

"C:\Program Files (x86)\nodejs\node.exe" app.js %*

Another alternative is this very simple C# app which will start Node using its own filename + .js as the script to run, and pass along any command line arguments.另一种选择是这个非常简单的 C# 应用程序,它将使用自己的文件名 + .js作为要运行的脚本启动 Node,并传递任何命令行参数。

class Program
{
    static void Main(string[] args)
    {
        var info = System.Diagnostics.Process.GetCurrentProcess();
        var proc = new System.Diagnostics.ProcessStartInfo(@"C:\Program Files (x86)\nodejs\node.exe", "\"" + info.ProcessName + ".js\" " + String.Join(" ", args));
        proc.UseShellExecute = false;
        System.Diagnostics.Process.Start(proc);
    }
}

So if you name the resulting EXE "app.exe", you can type app arg1 ... and Node will be started with the command line "app.js" arg1 ... .因此,如果您将生成的 EXE 命名为“app.exe”,则可以键入app arg1 ...并且 Node 将使用命令行"app.js" arg1 ... Note the C# bootstrapper app will immediately exit, leaving Node in charge of the console window.请注意,C# 引导程序应用程序将立即退出,让 Node 负责控制台窗口。

Since this is probably of relatively wide interest, I went ahead and made this available on GitHub , including the compiled exe if getting in to vans with strangers is your thing.由于这可能是相对广泛的兴趣,我继续在 GitHub 上提供了它,包括编译的 exe,如果你喜欢和陌生人一起上货车的话。

Haven't tried it, but nexe looks like nexe can do this:没试过,但 nexe 看起来像 nexe 可以做到这一点:

https://github.com/crcn/nexe https://github.com/crcn/nexe

Since this question has been answered, another solution has been launched.既然已经回答了这个问题,又推出了另一种解决方案。

https://github.com/appjs/appjs https://github.com/appjs/appjs

At the time of this writing, this is the end-all solution for packaging node.js apps through a stripped down chromium package compiled into an executable.在撰写本文时,这是通过编译为可执行文件的精简铬包打包 node.js 应用程序的最终解决方案。

Edit: AppJS is no longer active, but itself suggests a fork called deskshell.编辑:AppJS 不再处于活动状态,但它本身暗示了一个名为deskshell 的叉子。

https://github.com/sihorton/appjs-deskshell/ https://github.com/sihorton/appjs-deskshell/

There are a lot of good answers here, but they're not all as straightforward as JXcore .这里有很多很好的答案,但它们并不像JXcore那样直接。

Once you have JXcore installed on windows, all you have to do is run:在 Windows 上安装 JXcore 后,您所要做的就是运行:

jx package app.js "myAppName" -native

This will produce a .exe file that you can distribute and can be executed without any external dependencies whatsoever (you don't even need JXcore nor Node.js on the system).这将生成一个 .exe 文件,您可以分发该文件并且可以在没有任何外部依赖的情况下执行该文件(您甚至不需要系统上的 JXcore 或 Node.js)。

Here's the documentation on that functionality: http://jxcore.com/packaging-code-protection/#cat-74这是有关该功能的文档: http : //jxcore.com/packaging-code-protection/#cat-74

Edit 2018编辑 2018

That project is now dead but it is still hosted here: https://github.com/jxcore/jxcore-release (thanks @Elmue)该项目现已死亡,但仍托管在此处: https : //github.com/jxcore/jxcore-release (感谢@Elmue)

Try disclose : https://github.com/pmq20/disclose尝试disclosehttps : //github.com/pmq20/disclose

disclose essentially makes a self-extracting exe out of your Node.js project and Node.js interpreter with the following characteristics, disclose本质上从您的 Node.js 项目和 Node.js 解释器中制作了一个自解压的 exe,具有以下特征,

  1. No GUI.没有图形用户界面。 Pure CLI.纯 CLI。
  2. No run-time dependencies没有运行时依赖
  3. Supports both Windows and Unix支持 Windows 和 Unix
  4. Runs slowly for the first time (extracting to a cache dir), then fast forever第一次运行缓慢(提取到缓存目录),然后永远快速

Try node-compiler : https://github.com/pmq20/node-compiler尝试node-compilerhttps : //github.com/pmq20/node-compiler

I have made a new project called node-compiler to compile your Node.js project into one single executable.我创建了一个名为node-compiler的新项目来将您的 Node.js 项目编译成一个可执行文件。

It is better than disclose in that it never runs slowly for the first time, since your source code is compiled together with Node.js interpreter, just like the standard Node.js libraries.disclose它更好,因为它从不第一次运行缓慢,因为您的源代码是与 Node.js 解释器一起编译的,就像标准的 Node.js 库一样。

Additionally, it redirect file and directory requests transparently to the memory instead of to the file system at runtime.此外,它在运行时将文件和目录请求透明地重定向到内存而不是文件系统。 So that no source code is required to run the compiled product.这样就不需要源代码来运行编译后的产品。

How it works: https://speakerdeck.com/pmq20/node-dot-js-compiler-compiling-your-node-dot-js-application-into-a-single-executable工作原理: https : //speakerdeck.com/pmq20/node-dot-js-compiler-compiling-your-node-dot-js-application-into-a-single-executable

Comparing with Similar Projects,与同类项目相比,

  • pkg( https://github.com/zeit/pkg ): Pkg hacked fs.* API's dynamically in order to access in-package files, whereas Node.js Compiler leaves them alone and instead works on a deeper level via libsquash. pkg( https://github.com/zeit/pkg ):Pkg 动态地入侵了 fs.* API 以访问包内文件,而 Node.js Compiler 不理会它们,而是通过 libsquash 在更深层次上工作。 Pkg uses JSON to store in-package files while Node.js Compiler uses the more sophisticated and widely used SquashFS as its data structure. Pkg 使用 JSON 来存储包内文件,而 Node.js Compiler 使用更复杂和广泛使用的 SquashFS 作为其数据结构。

  • EncloseJS( http://enclosejs.com/ ): EncloseJS restricts access to in-package files to only five fs.* API's, whereas Node.js Compiler supports all fs.* API's. EncloseJS( http://enclosejs.com/ ):EncloseJS 将对包内文件的访问限制为仅五个 fs.* API,而 Node.js 编译器支持所有 fs.* API。 EncloseJS is proprietary licensed and charges money when used while Node.js Compiler is MIT-licensed and users are both free to use it and free to modify it. EncloseJS 是专有许可的,使用时收费,而 Node.js 编译器是 MIT 许可的,用户可以免费使用它,也可以免费修改它。

  • Nexe( https://github.com/nexe/nexe ): Nexe does not support dynamic require because of its use of browserify, whereas Node.js Compiler supports all kinds of require including require.resolve. Nexe( https://github.com/nexe/nexe ):Nexe 不支持动态 require,因为它使用了 browserify,而 Node.js Compiler 支持包括 require.resolve 在内的所有类型的 require。

  • asar( https://github.com/electron/asar ): Asar uses JSON to store files' information while Node.js Compiler uses SquashFS. asar( https://github.com/electron/asar ):Asar 使用 JSON 来存储文件信息,而 Node.js Compiler 使用 SquashFS。 Asar keeps the code archive and the executable separate while Node.js Compiler links all JavaScript source code together with the Node.js virtual machine and generates a single executable as the final product. Asar 将代码存档和可执行文件分开,而 Node.js Compiler 将所有 JavaScript 源代码与 Node.js 虚拟机链接在一起,并生成单个可执行文件作为最终产品。

  • AppImage( http://appimage.org/ ): AppImage supports only Linux with a kernel that supports SquashFS, while Node.js Compiler supports all three platforms of Linux, macOS and Windows, meanwhile without any special feature requirements from the kernel. AppImage( http://appimage.org/ ):AppImage 仅支持内核支持 SquashFS 的 Linux,而 Node.js Compiler 支持 Linux、macOS 和 Windows 三个平台,同时对内核没有任何特殊功能要求。

I'm recommending you BoxedApp for that.我为此向您推荐 BoxedApp。 It is a commercial product that working very well.它是一种运行良好的商业产品。 It works for any NodeJS app.它适用于任何 NodeJS 应用程序。 The end-user will get just one EXE file for your app.最终用户将只获得一个适用于您的应用程序的 EXE 文件。 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.例如,在 Electron 中,最终用户需要安装/解压缩您的应用程序,他将看到您代码的所有源文件。

BoxedApp It is packaging all the files and dependencies that your NodeJS app needs. BoxedApp 它打包了您的 NodeJS 应用程序所需的所有文件和依赖项。 It supports compressions, and the compiled file works on Windows XP+它支持压缩,编译后的文件适用于 Windows XP+

When you use it, be sure to add Node.EXE to the compiled app.使用的时候一定要在编译好的app中添加Node.EXE。 Choose a node version that supports Windows XP (If you need this)选择支持 Windows XP 的节点版本(如果需要)

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.有时你的应用程序有文件依赖,所以在 BoxedApp 中你可以添加任何文件夹和文件作为依赖,例如,你可以插入一个设置文件。

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.请注意:通常我会推荐开源/免费软件,但在这种情况下,我没有找到任何可以完成工作的东西。

Try nexe which creates a single executable out of your node.js apps尝试使用 nexe 从您的 node.js 应用程序中创建一个可执行文件

https://github.com/nexe/nexe https://github.com/nexe/nexe

I did find any of these solutions met my requirements, so made my own version of node called node2exe that does this.我确实发现这些解决方案中的任何一个都满足了我的要求,因此制作了我自己的名为 node2exe 的节点版本来执行此操作。 It's available from https://github.com/areve/node2exe它可以从https://github.com/areve/node2exe 获得

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. 1- NW.js :让您直接从 DOM 调用所有 Node.js 模块,并启用一种使用所有 Web 技术编写应用程序的新方法。

2- Electron : Build cross platform desktop apps with JavaScript, HTML, and CSS 2- Electron :使用 JavaScript、HTML 和 CSS 构建跨平台桌面应用程序

Here is a good comparison between them: NW.js & Electron Compared .这是它们之间的一个很好的比较: NW.js 和 Electron 比较 I think NW.js is better and it also provides an application to compile JS files.我认为 NW.js 更好,它还提供了一个编译 JS 文件的应用程序。 There are also some standalone executable and installer builders like Enigma Virtual Box .还有一些独立的可执行文件和安装程序构建器,例如Enigma Virtual Box They both contain an embedded version of Chrome which is unnecessary for server apps.它们都包含一个嵌入式版本的 Chrome,这对于服务器应用程序来说是不必要的。

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. node-compiler :为 Node.js 设计的 Ahead-of-time (AOT) 编译器,它可以正常工作。

Nexe : create a single executable out of your node.js apps Nexe :从您的 node.js 应用程序中创建一个可执行文件

In this category, I believe node-compiler is better which supports dynamic require and native node modules.在这个类别中,我认为 node-compiler 更好,它支持动态 require 和 native node 模块。 It's very easy to use and the output starts at 25MB.它非常易于使用,输出大小为 25MB。 You can read a full comparison with other solutions in Node Compiler page.您可以在 Node Compiler 页面中阅读与其他解决方案的完整比较。 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.我对 Nexe 的了解不多,但就目前而言,Node Compiler 似乎没有使用 V8 快照功能将 js 文件编译为二进制格式,但它计划用于版本 2。它还将具有内置的安装程序构建器。

Got tired of starting on win from command prompt then I ran across this as well.厌倦了从命令提示符开始赢,然后我也遇到了这个问题。 Slightly improved ver.稍微改进了ver. over what josh3736 .在什么josh3736 This uses an XML file to grab a few settings.这使用一个 XML 文件来获取一些设置。 For example the path to Node.exe as well as the file to start in the default app.js.例如, Node.exe的路径以及要在默认 app.js 中启动的文件。 Also the environment to load (production, dev etc) that you have specified in your app.js (or server.js or whatever you called it).还有你在 app.js(或 server.js 或任何你称之为的)中指定的加载环境(生产、开发等)。 Essentially it adds the NODE_ENV={0} where {0} is the name of your configuration in app.js as a var for you.本质上,它添加了NODE_ENV={0} ,其中 {0} 是 app.js 中的配置名称,作为您的 var。 You do this by modifying the "mode" element in the config.xml.您可以通过修改 config.xml 中的“mode”元素来完成此操作。 You can grab the project here ==> github .你可以在这里获取项目 ==> github Note in the Post Build events you can modify the copy paths to auto copy over your config.xml and the executable to your Nodejs directory, just to save a step.请注意,在 Post Build 事件中,您可以修改复制路径以自动复制您的 config.xml 和可执行文件到您的Nodejs目录,只是为了节省一个步骤。 Otherwise edit these out or your build will throw a warning.否则将这些编辑掉,否则您的构建将发出警告。

var startInfo = new ProcessStartInfo();
        startInfo.FileName = nodepath;
        startInfo.Arguments = apppath;
        startInfo.UseShellExecute = false;
        startInfo.CreateNoWindow = false;
        startInfo.WindowStyle = ProcessWindowStyle.Hidden;

        if(env.Length > 0)
            startInfo.EnvironmentVariables.Add("NODE_ENV", env);

        try
        {
            using (Process p = Process.Start(startInfo))
            {
                p.WaitForExit();
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message.ToString(), "Start Error", MessageBoxButtons.OK);
        }

I was using below technology:我正在使用以下技术:

  1. @vercel/ncc (this make sure we bundle all necessary dependency into single file) @vercel/ncc (这确保我们将所有必要的依赖项捆绑到一个文件中)
  2. pkg (this to make exe file) pkg (这个用来制作exe文件)

Let do below:让我们在下面做:

  1. npm i -g @vercel/ncc npm i -g @vercel/ncc

  2. ncc build app.ts -o dist (my entry file is app.ts, output is in dist folder, make sure you run in folder where package.json and app.ts reside , after run above you may see the index.js file in the folder dist) ncc build app.ts -o dist(我的入口文件是app.ts,输出在dist文件夹中,确保你在package.json和app.ts所在的文件夹中运行,上面运行后你可能会看到index.js文件在文件夹 dist 中)

  3. npm install -g pkg (installing pkg) npm install -g pkg(安装 pkg)

  4. pkg index.js (make sure you are in the dist folder above) pkg index.js(确保您在上面的 dist 文件夹中)

There may be many other options but to my knowledge, there is one project in active development on GitHub https://github.com/zeit/pkg .可能还有许多其他选择,但据我所知,GitHub https://github.com/zeit/pkg上有一个项目正在积极开发中。 You can play with it.你可以玩它。 One more at https://github.com/nexe/nexe but not in active development.https://github.com/nexe/nexe 上还有一个,但不在积极开发中。

There is an opensource build tool project called nodebob .有一个名为nodebob的开源构建工具项目。 I assume that working platform windows,我假设工作平台窗口,

  1. simply clone or download project只需克隆或下载项目
  2. copy all node-webkit project files of yours into the app folder.将您的所有 node-webkit 项目文件复制到 app 文件夹中。
  3. run the build.bat script.运行 build.bat 脚本。

You will find the executable file inside the release folder.您将在发布文件夹中找到可执行文件。

Note: You need python and pip (or easy_install) as well for this to work.注意:您还需要 python 和 pip(或 easy_install)才能使其工作。

Create a node virtual environment using nodeenv (install using python -m pip install nodeenv ) (make using python -m nodeenv envname )使用nodeenv创建节点虚拟环境(使用python -m pip install nodeenv )(使用python -m nodeenv envname进行python -m pip install nodeenv

Create a .bat file launching the code using the node virtual environment's exe file (stored in ./envname/Scripts/node.exe ), then use some bat to exe converter ( http://www.battoexeconverter.com/ ) idk then distribute all the files except the bat file use the exe converted file instead by making them into a installer using some program.使用节点虚拟环境的 exe 文件(存储在./envname/Scripts/node.exe )创建一个 .bat 文件启动代码,然后使用一些 bat 到 exe 转换器( http://www.battoexeconverter.com/)idk然后分发除 bat 文件之外的所有文件,使用 exe 转换文件,而不是通过使用某些程序将它们制作成安装程序。 There you go.你去吧。

Currently, I think the way to go is deno目前,我认为要走的路是deno

This is这是

deno compile mainProgram.js

Existing node projects may need some sort of conversion, at least for require statements (convert node projects to deno)现有的节点项目可能需要某种转换,至少对于 require 语句(将节点项目转换为 deno)

One way to do this is to publish your code as an NPM module, and supply NPM with a bin file in the package.json with "bin": "app.js" 1 One way to do this is to publish your code as an NPM module, and supply NPM with a bin file in the package.json with "bin": "app.js" 1

For users to install your CLI, they will have to have node installed and run npm i -g [packageName] (-g is for global)要让用户安装 CLI,他们必须安装节点并运行npm i -g [packageName] (-g 用于全局)

this answer is very simple but has the downside of requiring node to be installed.这个答案非常简单,但缺点是需要安装节点。

If you want your app to actually be an executable without the help of node or NPM, i would recommend nexe如果您希望您的应用程序在没有节点或 NPM 帮助的情况下实际上是可执行文件,我会推荐nexe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM