Introduction to ElectronJS
If you are interested in using Web Development skills for developing apps for different desktop platforms like Windows, Linux or macOS, Electron is the perfect framework that suits your needs. Let’s start with a brief introduction to Electron.
ElectronJS: Electron was developed lately in 2013 by the open-source and version control giant, GitHub. Electron uses NodeJs in its core to serve pages built on HTML and CSS as a desktop app. This implies that developers comfortable in HTML5 or Android Development can easily switch their platform to Electron.
The Electron app may be categorized into two main processes, namely, Main and Renderer process.
Performing Culture: There are two process in the Electron performing Culture:
BrowserWindow instances. Individual BrowserWIndow instance renderes a webpage in its renderer process. Destroying a BrowserWindow instance implies that the corresponding renderer process is also terminated.Electron supports various APIs for both the main and renderer processes, which helps to interact with the desktop operating system and its resources.
Prerequisites: The main prerequisites which may be considered important for starting on with Electron are listed below.
- HTML and CSS for User Interface.
- JavaScript as a main language.
- Node.js and npm
Installing Electron: Let’s start with the building blocks of development with Electron.
node -v
npm -v
npm install electron --save-dev
{ "name": "electronapp", "version": "1.0.0", "description": "Electron application", "main": "main.js", "scripts": { "start": "electron ." }, "keywords": [ "Electron" ], "author": "xyz", "devDependencies": { "electron": "^7.1.7" } } |
const { app, BrowserWindow } = require('electron') let win function createWindow () { // Create the browser window. win = new BrowserWindow({ width: 800, height: 600, icon: ( './icon.png'), webPreferences: { nodeIntegration: true } }) // and load the index.html of the app. win.loadFile('./index.html') //win.loadURL('https://google.com/') // Open the DevTools. win.webContents.openDevTools() // Emitted when the window is closed. win.on('closed', () => { // Dereference the window object, usually you would store windows // in an array if your app supports multi windows, this is the time // when you should delete the corresponding element. win = null }) } // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.on('ready', createWindow) // Quit when all windows are closed. app.on('window-all-closed', () => { // On macOS it is common for applications and their menu bar // to stay active until the user quits explicitly with Cmd + Q if (process.platform !== 'darwin') { app.quit() } }) app.on('activate', () => { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (win === null) { createWindow() } }) |
<!DOCTYPE HTML> <html> <head> <title>my first electron app</title> </head> <body> <h1>my first electron app</h1> </body> </html> |
npm install --unsafe-perm=true |
will download necessary node_modules, required by electron to render a page.
npm run start, start being the script which we have defined in package.json.
Output:

References: https://electronjs.org/docs/tutorial/first-app#installing-electron
Recommended Posts:
- About Panel in ElectronJS
- Emulation in ElectronJS
- How to take Screenshots in ElectronJS ?
- Hot Reload in ElectronJS
- Clipboard API in ElectronJS
- Generate PDF in ElectronJS
- Geo Information in ElectronJS
- Printing in ElectronJS
- Save Files in ElectronJS
- Dynamic Styling in ElectronJS
- Keyboard Events in ElectronJS
- Zoom Functionality in ElectronJS
- Integrate Angular 7 with ElectronJS
- File Upload in ElectronJS
- Keyboard Shortcuts in ElectronJS
- Network Logging in ElectronJS
- Custom Notifications in ElectronJS
- Custom Messages in ElectronJS
- Desktop Operations in ElectronJS
- Managing Themes in ElectronJS
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


