program tip

node.js 앱에서 exe 파일을 만드는 방법은 무엇입니까?

radiobox 2020. 7. 27. 07:49
반응형

node.js 앱에서 exe 파일을 만드는 방법은 무엇입니까?


내가 쓴 노드 앱이 있는데 다음과 같이 실행됩니다.

node.exe app.js inputArg

이것을 .exe 자체로 패키지 할 수있는 방법이 있습니까? 그래서 나는 이런 식으로 할 수 있습니까?

App.exe inputArg

배치 파일을 사용하여이를 가짜로 만드는 방법이 있으므로 다음과 같이하십시오.

App.bat inputArg

그러나 이것은 폴더에 모든 종속성과 노드가 있어야하며 이상적이지 않습니다.


무료 및 상업용의 몇 가지 대안이 있습니다. 나는 그것들을 사용하지 않았지만 이론적으로는 작동해야합니다.

대부분의 경우 배치 파일을 기본 실행 파일로 유지 한 다음 node.exe 및 스크립트를 번들로 제공해야합니다.

스크립트에 따라 JSDB 로 이식하는 옵션도 있습니다.이 옵션 은 단순히 리소스를 추가 하여 실행 파일 을 쉽게 생성수있는 방법을 지원 합니다.

세 번째 준 솔루션은 노드를 어딘가에두고이 C:\utils폴더를 PATH환경 변수에 추가하는 것 입니다. 그런 다음 해당 디렉토리에 .bat 파일을 생성하여 node + 선호하는 스크립트를 실행합니다. 커피 스크립트가 coffeeWindows에서 이런 식으로 작동하고 있습니다. 이 설정은 배치 파일, vb 스크립트 또는 설치 프로그램으로 자동화 할 수 있습니다.


내가 사용한 솔루션은 Roger Wang의 node-webkit 입니다.

이것은 nodejs 앱을 패키징하고 배포하는 환상적인 방법이며, 전체 앱을 단일 실행 파일로 "번들"하는 옵션도 제공합니다. 그것은 윈도우, 맥 및 리눅스를 지원합니다.

다음 은 노드-웹킷 앱 배포를위한 다양한 옵션에 대한 몇 가지 문서입니다. 간단히 말해서 다음을 수행하십시오.

  1. 루트에 package.json을 사용하여 모든 파일을 압축하십시오.
  2. 확장자를 .zip에서 .nw로 변경
  3. 복사 / b nw.exe + app.nw app.exe

추가 메모와 마찬가지로-이것을 사용하여 여러 프로덕션 상자 / 설치 CD 응용 프로그램을 제공했으며 훌륭하게 작동했습니다. 동일한 앱은 Windows, Mac, Linux 및 웹에서 실행됩니다.


이 질문에 걸려 넘어지는 사람에게는 이제 노드 프로젝트에서 exes를 만드는 두 개의 프로젝트 PkgElectron.atom.io 가 있습니다.

  1. Pkg 는 프로젝트를 네이티브 코드로 컴파일하고 자산과 nodejs 설치도 포함합니다 (시스템은 .exe를 실행하기 위해 nodejs를 설치할 필요가 없습니다). 소스 코드는 포함되지 않습니다. 결과 실행 파일은 Windows 전용 (.exe)입니다. 모든 플랫폼이 지원됩니다. 이제 상용 제품에 대한 라이센스가 필요합니다. 완전 오픈 소스.
  2. Electron.atom.io 는 압축되지 않고 .exe를 생성하지는 않지만 응용 프로그램배포 하는 방법을 제공하므로 nodejs 응용 프로그램을 배포하는 데 사용할 수 있습니다 . 장점은 전자가 다중 플랫폼 (windows, mac osx, linux)이며 소스 코드가 포함될 것이라는 단점이 있습니다. 심지어도 아파르 아카이브에 앱을 배포하는 방법을 제공하기는 어렵습니다 . 방탄하지는 않지만 여전히 소스보다 낫습니다.

기본적으로 Windows는 .js파일을 Microsoft의 독립형 JS 런타임 엔진 인 Windows Script Host연결 합니다 . 명령 프롬프트에서 script.js 를 입력 하거나 .js탐색기 에서 파일을 두 번 클릭 하면 스크립트가에 의해 실행됩니다 wscript.exe.

이것은 전역 설정으로 로컬 문제를 해결할 수 있지만 대신 파일을 연결할 있으므로 명령 프롬프트에서 script.js 를 입력 하거나 스크립트에 항목을 두 번 클릭 / 드래그하면 Node로 파일이 시작됩니다..jsnode.exe

물론 나와 같은 .js파일을 편집기와 연결하여 파일을 두 번 클릭하면 즐겨 찾는 텍스트 편집기가 열리면이 제안은 그리 좋지 않습니다. 명령 행 요구 사항을 해결하지는 않지만 "Execute with Node"를 마우스 오른쪽 단추로 클릭 한 메뉴 항목.js파일에 추가 할 수도 있습니다 .


가장 간단한 해결책은 배치 파일을 사용하는 것입니다. 스크립트가있는 폴더에 Node 사본이 없어도됩니다. Node 실행 파일을 절대 참조하십시오.

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

또 다른 대안은이 매우 간단한 C # 앱으로 자체 파일 이름 + .js를 실행할 스크립트로 사용하여 노드를 시작 하고 명령 줄 인수를 전달합니다.

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);
    }
}

결과 EXE 이름을 "app.exe" app arg1 ...로 지정하면 명령 줄에서 Node를 입력 할 수 있습니다 "app.js" arg1 .... C # 부트 스트 래퍼 앱은 즉시 종료되어 노드가 콘솔 창을 담당하게합니다.

이것은 아마도 상대적으로 관심이 많을 것이므로, GitHub 에서 이것을 사용 가능 하게 만들었습니다 . 낯선 사람과 밴에 들어가는 것이 당신의 일이라면 컴파일 된 exe를 포함합니다 .


The best tool I know is NodeJS tool: 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

to create executables for macOS, Linux and 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.


Haven't tried it, but nexe looks like nexe can do this:

https://github.com/crcn/nexe


Since this question has been answered, another solution has been launched.

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.

Edit: AppJS is no longer active, but itself suggests a fork called deskshell.

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


There are a lot of good answers here, but they're not all as straightforward as JXcore.

Once you have JXcore installed on windows, all you have to do is run:

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).

Here's the documentation on that functionality: http://jxcore.com/packaging-code-protection/#cat-74

Edit 2018

That project is now dead but it is still hosted here: https://github.com/jxcore/jxcore-release (thanks @Elmue)


Try disclose: https://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,

  1. No GUI. Pure CLI.
  2. No run-time dependencies
  3. Supports both Windows and 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

I have made a new project called node-compiler to compile your Node.js project into one single executable.

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.

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

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 uses JSON to store in-package files while Node.js Compiler uses the more sophisticated and widely used SquashFS as its data structure.

  • 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 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.

  • 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.

  • asar(https://github.com/electron/asar): Asar uses JSON to store files' information while Node.js Compiler uses 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.

  • 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.


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.


I did find any of these solutions met my requirements, so made my own version of node called node2exe that does this. It's available from 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.

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.


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

https://github.com/nexe/nexe


Got tired of starting on win from command prompt then I ran across this as well. Slightly improved ver. over what josh3736. This uses an XML file to grab a few settings. For example the path to Node.exe as well as the file to start in the default 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). Essentially it adds the NODE_ENV={0} where {0} is the name of your configuration in app.js as a var for you. You do this by modifying the "mode" element in the config.xml. You can grab the project here ==> 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. 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);
        }

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.


There is an opensource build tool project called 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.
  3. run the build.bat script.

You will find the executable file inside the release folder.

참고URL : https://stackoverflow.com/questions/8173232/how-to-make-exe-files-from-a-node-js-app

반응형