What is Electron? Electron is a platform that allows you to build cross platform applications with HTML, JavaScript and CSS. It's built on top of Node JS and Chromium (a web browser).
Node handles all your system calls and Chromium handles all the user interface elements and the majority of data processing. When you build you project it is turned into an executable. This executable contains a node server, a web browser and your web application. Note that the Node server is only accessible to your application.
This means that your app essentially lives inside a browser. This browser however has no user interface elements of its own and so looks and behaves more like a traditional desktop application.
Watch this video to find out more:
So when one of my mates brought up Electron and the preceding the conversation when a little like this:
So it's like Java?
Well yes, no and sort of.
Yes, like Java you write your application once and it's capable of running on the 3 major desktop operating systems; Windows, Mac OS and Linux.
No. With Electron you must compile your application for each platform you want to run it on. When you compile an electron project it compiles your code into a program which contains a browser and a node server. This compiled program hosts your web code. With Java, you compile Java Virtual Machine (JVM) bytecode. The Bytecode is then run in the JVM. The JVM acts as a middleman between Java bytecode and the Operating System.
Sort of. It's like Java in the sense that the browser element of Eelectron performs a similar task to the Java Virtual Machine. Just like Java, electron apps aren't as quick as applications that are compiled to executable machine code. Electron based programs are web applications disguise as a desktop programs.
What are the benefits or using Electron?
Electron is a great platform for writing applications. After watching the video you've probably realised electron applications are cross platform without the need for you to rewrite code. It runs JavaScript on both the front end and back end. The learning curve isn't that steep. If you well versed in web programming then electron is relatively easy to pick up and lean.
You can use HTML and CSS to quickly and easily build a GUI. It's open source so it's always getting updates and bug fixes. Just because it's open source doesn't mean you can't use your Electron program commercially. But it is always best to check licenses with a legal professional if you're ever unsure of how your specific usage of copyrighted material is covered.
The front end JavaScript is compatible with all standard web JavaScript libraries. As Electron uses Node you have access to a wide variety of third party libraries which allows you to quickly extend Node's base feature set. Notably there are several database libraries that make integrating database packages like MySQL, or SQLite easy. Many of the libraries are published under an MIT licence which make them easy to integrate into commercial products.
What might prevent you from considering switching to electron?
Electron's documentation; at the moment, isn't all up to date. Often times the Node documentation is leagues better than electrons. I would definitely recommend looking at a few node tutorials before starting your first electron project. There are also a lot of electron tutorials that are based on older versions and may things shown in them have drastically changed.
Node does require you to use the command line which may make some programmers uncomfortable. You are also somewhat limited to the constraints of HTML and JS. There are things you can do in C/C++/C#/Objective C or Java/Python or many other lower level languages that you simply can't do with web technologies. Node does use some concepts that are related to system programming; which can make using it a little challenging. This can result in programmers getting tripped up by concepts that don't naturally exists in web based JavaScript.
Licensing your product can be a little tricky. While many open source licences are compatible with each other there are some that aren't. Before adding a library to your project you need to check that all the licences that you are using are compatible with one another and that licence you're selling your software under is compatible with all the third-party technologies your project uses.
So server side JavaScript?
There are four types of people those who:
- like JavaScript
- dislike JavaScript
- like server side JavaScript
- dislike server side JavaScript
While I at first didn't like Node, it does grow on you after a while.
Node certainly isn't perfect and it can be flawed at times; particularly if you don't understand some of Nodes fundamental design choices. It's a bit of a love hate relationship for me at the moment. I like it because it's quick to pick up and relatively easy to learn. I dislike it because Node is clearly designed to run as server and when using Node to interact with an operating system it can be frustrating at times. Node is also a little harder to get going on Windows than it is on Linux or Mac OS.
So give electron a look and decide if it's suitable for you.
How can I learn more about electron? Visit http://electron.atom.io/
How do I get started? See the quick start guide https://github.com/electron/electron-quick-start
Zach Radloff lives on the Gold Coast and is studying IT and Multimedia at university, and is also a qualified Live Production, Theatre and Events Technician.
Zach Radloff's previous articles may be viewed at www.pressserviceinternational.org/zach-radloff.html