Better Programming

Advice for programmers.

Follow publication

Member-only story

Create a Basic Desktop Application With Electron

Pavel Ilin
Better Programming
Published in
2 min readOct 2, 2020
large version of the Electron logo on a white background
Image source: Wikimedia

If you work with JavaScript, you think that it’s a language of the web and if you would like to create a desktop application, you have to learn C# or something like that. But don’t despair! You can use the Electron.js library to create desktop solutions.

Let’s see how we can do it!

Setup

Essentially, Electron is a Node.js application. Like any Node application, it will have a package.json file with instructions and a list of dependencies.

Let’s create a new Node project:

yarn init// ornpm init// I prefer yarn

It will create a package.json with initial information about the new application. And we need to add a start to a scripts list in our package.json so we can run the Electron library. This is how the initial package.json looks:

Next we need to install the Electron library:

yarn add electron

Application

Now when the environment is ready, we can start working on the application. The first step will be creating index.js (or any name you specify in the package.json) file and importing the Electron library and its methods:

const { app, BrowserWindow } = require(‘electron’)

Next let’s declare parameters of out the application window and which HTML file to load with a simple JavaScript function:

Yes, we use HTML and Chrome to create desktop applications. Life can be weird, don’t worry.

Next we initialize our application and invoke the createWindow function:

app.whenReady().then(createWindow)

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Pavel Ilin
Pavel Ilin

Written by Pavel Ilin

Software Engineer, Researcher and Transhumanist.

Write a response