Golang in NodeJS Applications: Part 3 (Wails)
Previously I wrote about leveraging Golang through FFI, NAPI and Web Assembly. Now it’s time to talk about an existing solution that provides the best of both worlds: An electron alternative for Go - Wails
What is Electron?
Electron is a toolkit for building desktop applications usign web technologies (Javascript, HTML). Essentially it is a web browser engine with node.js and OS APIs under the hood. There are a lot of apps made with Electron like Discord, Notion, etc.
While Electron has a rich ecosystem and companies using it for their applications, there is one big shorcoming - Electron beyond NodeJS is very hard. Any code that require you to interact with anything other than web or node APIs/ABIs is something that usually requires you to deal with C++ bindings. For example - concurrency (multreading), working with different file formats, vector math, etc.
Wails
Wails provides the same capabilities as Electron, but seamlesly integrates Golang runtime in your application which makes it possible to fully leverage Go features and existing libraries.
From the point of developer experience, Wails is easy to get started and use for anyone familiar with Go and web development. The features like Go struct to TypeScript model generation and support for all major web frameworks makes the dev. experience simple and fun.
For myself, Wails turned out even easier to get started than Electron. Only two comands and you’re ready:
go install github.com/wailsapp/wails/v2/cmd/wails@latest
wails init -n my-app -t svelte
And to start the project:
cd my-app
wails dev
The expected downside of using Golang may be some short delays on compilation when you change the Go code. With JavaScript the experience is the same as with Electron or any web app.
In conlusion
My post turned out to look like a short promo in part because the Wails team did a good job describing all details in their docs and I don’t want to repeat them. All I want to say is that Wails is a good replecment for Electron and at the time it is the first choice for me to build desktop interfaces.