将 Node.js web 应用程序打包为普通的桌面应用程序

我搜索了一下,但是找不到现有的工具。

我有一个 Node.js 网络服务器,它是专门设计来运行在你自己的电脑上,为你做一些时髦的事情。如果我能够双击 MySnazzyThing.app而不是安装 Node.js 和 npm 并在命令行上运行 node mysnazzyapp.js,那将是非常棒的。

.app可执行文件将对 Node.js 服务器进行后台处理,并打开一个简单的本机 WebKit窗口,该窗口将显示如果我在命令行上运行,localhost:3000上通常会出现什么。

这个本地应用程序可以通过 Mac 应用程序商店发布。

是否有这样的工具存在? 或者是否有任何技术原因使得它不能像我想象的那样工作?

38551 次浏览

I suggest looking into Topcube. Its goal is to give Node.js developers a way to have a desktop GUI to their Node.js servers using HTML5 + CSS 3 as the GUI platform.

Topcube at GitHub.

Currently there are a plethora of ways to accomplish this.

The clear winner in the space of packaging a Node.js + HTML5 application, is currently Electron (used by Atom, Visual Studio Code, Slack, Discord, etc.).

You can also use any other language packaged as an application (using tools for those languages/stacks), and check for a node installation, launch the "server" script with Node.js, then launch the default browser (or some web view component, by some other means), finally set location to the Node.js service. This is a very lightweight and efficient method, however not as well integrated with the OS as a solution like Electron.

The primary competitor to Electron here, is NW.js. As far as I can tell, the main feature that NW.js has that Electron does not (yet) is compilation/obfuscation. While Electron makes auto updates easy.

Option 1: Electron (formerly atom-shell)

This is the shell that GitHub's Atom and Microsoft's Code editors use. It’s very similar to node-webkit, though it will run the script first, and you have to create a view/window for the user. There are some other minor differences, but it's worth looking at.


Option 2: NW.js formerly node-webkit

The gist is that it basically extends the JavaScript engine for you to write a web-based application supporting Node.js' extended object model, and modules... you then package your package.json start.html modules and JavaScript files into a ZIP file (with the .nw extension) and run it with nw(.exe) .. there are Windows, Mac and Linux builds available.


Option 3: Neutralinojs Github

Neutralinojs is a lightweight and portable desktop application development framework. It lets you develop lightweight cross-platform desktop applications using JavaScript, HTML and CSS. You can extend Neutralinojs with any programming language (via extensions IPC) and use Neutralinojs as a part of any source file (via child processes IPC).


Option 4: MacGapNode (OS X only)

MacGap with Node.js integration (it seems to be getting stale)


Option 5: Tauri Github

Tauri is a toolkit that helps developers make applications for the major desktop platforms - using virtually any frontend framework in existence. The core is built with Rust and the CLI leverages Node.js making Tauri a genuinely polyglot approach to creating and maintaining great apps.


Aside: Services...

I can't speak for OS X on this as a .App, but it could well be possible to create a background service install in Node.js and a link to a "local" site on the desktop. Most browsers have an option to not show all the features (I know Firefox in particular does).

I know your question is to OS X in particular, but in Windows you can use NSSM to run anything as a service, and I have used it for Node.js-based services in Windows. I think some of the other options above are better depending on your needs though.


Removed:


This answer is copied for multiple questions, and these references are mostly for updating convenience.

You can accomplish this using AppJS.