独立的 Node.js 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13388108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 16:39:14  来源:igfitidea点击:

Standalone Node.js application

node.js

提问by Matthieu Napoli

I am considering developing a desktop application composed of 2 parts:

我正在考虑开发一个由两部分组成的桌面应用程序:

  • user interface (Java app for example)
  • back-end Node.js server
  • 用户界面(例如 Java 应用程序)
  • 后端 Node.js 服务器

The 2 parts connect through sockets. Don't ask why I know it's weird.

两部分通过插座连接。不要问为什么我知道这很奇怪。

I will want to be able to provide to customers the application with an installer. I don't want that users have to install Node.js themselves.

我希望能够向客户提供带有安装程序的应用程序。我不希望用户必须自己安装 Node.js。

Is there a way to have a Node.js server installed as standalone, i.e. no need to install Node.js globally on the system.

有没有办法将 Node.js 服务器安装为独立的,即不需要在系统上全局安装 Node.js。

This is a question for any (Windows, Linux, Mac OS X...) environment.

这是任何(Windows、Linux、Mac OS X...)环境的问题。

采纳答案by BadCanyon

You can bundle the binaries with your application. Won't have to install anything to run a Node app. The binaries are availableon the same page as the installers.

您可以将二进制文件与您的应用程序捆绑在一起。无需安装任何东西即可运行 Node 应用程序。二进制代码是可用的同一页上的安装程序。

You'll just have to know where the binaries are, but I assume you've got an installer that can put them somewhere known.

你只需要知道二进制文件在哪里,但我假设你有一个安装程序可以把它们放在已知的地方。

// To start the node process
$ /path/to/binaries/npm install
$ /path/to/binaries/node myApp.js

回答by CoolAJ86

Update 2017-05-04: And there's a new kid in town:

2017-05-04 更新:镇上有一个新孩子:

Update 2016-11-14: Nowadays Electron and nwjs seem like the best options.

2016 年 11 月 14 日更新:如今 Electron 和 nwjs 似乎是最好的选择。

Original:

原文

There are a number of steps you have to go through to create an installer and it varies for each Operating System. For Example:

要创建安装程序,您必须执行许多步骤,并且每个操作系统都会有所不同。例如:

回答by Sdedelbrock

Node-Webkitis an option, but it really isn't set-up to do a "server - client" type relationship.

Node-Webkit是一个选项,但它实际上并没有设置为执行“服务器 - 客户端”类型的关系。

Another option is packaging the node.js installers with you application installer. Then when the application boot you can spin up a node.js process. I know some developers have been doing this with titanium, here is a little bit more information information.

另一种选择是将 node.js 安装程序与您的应用程序安装程序一起打包。然后当应用程序启动时,您可以启动一个 node.js 进程。我知道一些开发人员一直在用钛做这个,这里有更多的信息信息

Hope this helps!

希望这可以帮助!

回答by rdrey

Here's an option: Light Tableis a node app, but installs nicely and integrates the GUI (webkit) cleanly on most OSs.

这是一个选项:Light Table是一个节点应用程序,但在大多数操作系统上安装良好并干净地集成了 GUI (webkit)。

To do this it leverages node-webkit. (Runs node code straight from an html page.) Here is the packaging documentation.

为此,它利用了node-webkit。(直接从 html 页面运行节点代码。)这是打包文档

回答by itamarb

Worth mentioning Electronmade by GitHub. Used for building Atom, Slack, Visual Studio Code and more.

值得一提的是 GitHub 制作的Electron。用于构建 Atom、Slack、Visual Studio Code 等。

回答by tomekwi

I've just stumbled upon nexe– a tool which “creates a single executable out of your node.js app”.

我刚刚偶然发现了nexe——一个“从你的 node.js 应用程序中创建单个可执行文件”的工具。

I haven't tried it out yet, but I guess that even works without an installer – producing just a single standalone binary.

我还没有尝试过,但我想即使没有安装程序也能工作——只生成一个独立的二进制文件。

回答by kub1x

I got here searching for Node.js desktop app framework (even though the question by OP about installing node.js server as a package, not about app with UI).

我在这里搜索 Node.js 桌面应用程序框架(尽管 OP 提出的问题是关于将 node.js 服务器作为包安装,而不是关于带有 UI 的应用程序)。

I'd like to mention Proton Nativeas it is missing here so far. It is still new, but looks promising. It lets you use React Native components to create desktop apps for various platforms (uses Qt under the hood).

我想提一下Proton Native,因为它到目前为止还没有出现。它仍然是新的,但看起来很有希望。它允许您使用 React Native 组件为各种平台创建桌面应用程序(在后台使用 Qt)。