Beyond the Browser: Taking JS to the Desktop

This is the latest editorial from the JS newsletter. You can subscribe here.

What do these four applications have in common: a Git GUI client, a streaming torrent client, an SQL analysis tool, and an email client? They are all desktop apps written in JavaScript. Up until relatively recently, desktop applications were (mostly) the domain of compiled languages such as C, C++ and C# and scripting languages such as JavaScript were confined to the web. Over time, browser APIs have become more powerful and JavaScript itself has improved, and web-based apps have become a viable replacement for many types of application that were traditionally confined to the desktop.

As JavaScript has continued to grow, both in capability and popularity, it’s pushed into new territory. A big development was the introduction of Node.js, taking JavaScript to the server, and since then, the Node runtime has become the basis for another expansion onto the desktop. The two main frameworks in this space are NW.js (formerly the node-webkit project) and Electron (formerly Atom Shell). NW.js is sponsored by Intel, who use it to great effect as the foundation for their mobile app development environment, XDK, while Electron is backed by GitHub and is the platform which their Atom text editor is built off.​

Both of these projects utilize the same basic technologies. Node.js provides access to lower level APIs for interacting with the host machine, such as the file system. This means your apps aren’t restricted to the usual sandboxed functionality of the browser, but can do a lot of the things a traditional desktop app can. Some variation of the Chromium browser runtime is used to render HTML markup to provide a GUI. This provides solid support for modern HTML and CSS, allowing you to create slick and stylish interfaces.

As you might expect, there are differences between the two frameworks. With Electron, your app runs a Node process which can, in turn, create new windows with HTML content. These windows run in separate processes, and closing them doesn’t terminate the main app process unless the developer specifically hooks into the window’s close event to do so. NW.js, on the other hand, launches a HTML file as the app’s entry point. The window can hook into Node functionality via an API that is made available in the global scope. There are some other differences in functionality that may affect which is more suitable for the use you have in mind.

Electron 1.0 was released earlier this month, marking an important milestone in the maturity of JavaScript on the desktop. Some important tooling has also been introduced, such as dedicated debugging tools (Devtron) and an integration test framework (Spectron). To coincide with this release, Chris Ward has taken a look at just how easy it is to get a simple, cross-platform desktop app up and running with Electron.

JavaScript continues to make inroads into territory once reserved for other languages - smartphones, drones and robots, IoT devices, and, of course, the desktop. Projects such as NW.js and Electron are a boon to those of us with a background in web development, allowing us to leverage our existing skillsets to create slick, cross-platform, offline applications. Have you tried your hand at building a desktop app yet? I’d love to hear your opinions about JS on the desktop, good or bad.

8 Likes

It’s been great to see really good examples of desktop apps built with web technologies, Atom was a real eye opener to me and has proven that web tech is indeed up to the task of building really high quality apps. As a web developer, Cordova and Electron offer new capabilities and opportunities for us to build apps, it makes a lot of sense for development teams to be able to write once and deploy anywhere.

ReactNative and projects like ReactNative Desktop are the alternative approach, using JavaScript and a subset of other web technologies(e.g. flexbox for layout) to compile to native targets so you’re getting platform specific components.

The web will win.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.