A Brief Intro to Electron.js for getting started

Sarthak Srivastav
Developers Stacks
Published in
2 min readFeb 18, 2019

So, this is not a long time before when I first came to know about electron.js. Before that time I was only into web development and had no idea about building android apps, desktop apps, etc. So, for a person like me, the tagline of electron.js was enough to enthrall me towards it.

Build cross platform desktop apps with JavaScript, HTML, and CSS

Getting Started

So, I will be giving a brief introduction to what electron basically is and what are some basic things to know about it to get started.
Electron is essentially a node development. To turn our operating system into an environment capable of building desktop apps with electron we merely need:
* Node.js
* OS command line client understanding and
* npm

  1. npm init
This is how you fill the package.json file in node and electron with npm init

2. npm install — save- dev electron

3. Electron development
The electron module exposes features in namespaces.
The lifecycle of the app: electron.app
The window can be created through electron.browserWindow
They both can be used in a file as:
const { app, browser window } = require(‘electron’);

4. npm start will run the app

5. Electron app architecture
So, every electron process runs with two processes, the main process, and the renderer process, that’s it.
Main process: In electron, the process that runs package.json’s main script is called the main process. There will only be one main process.
Renderer process: Since electron uses chromium for displaying web pages so chromium’s multi-process architecture is also used, hence each web page in electron runs in its own process called the renderer process.

6. Electron API’s
There are a number of API’s given in electron. Some can be used only in of the processes mentioned above and some can be used in both.
* remote module is used to use an API from main to the renderer and provides a simple way to do IPC(inter-process communication) between them.
* You can use Nodejs APIs like fs module, os module, etc. in both of the processes.

So, this is all about a brief introduction to electron

--

--