What is Electron.js? Beginner's Guide


What is Electron.js?

Electron.js is an open-source framework used for developing desktop applications using web technologies. Applications created with JavaScript, HTML, and CSS can run on different platforms such as Windows, MacOS, and Linux thanks to Electron. It allows developers to easily port their web applications to the desktop environment.

Main Features of Electron.js

Cross-Platform Support

Electron.js allows you to run your application on different operating systems after developing it once. In this way, you only need a single codebase to expand your user base.

Access to Operating System Features

When combined with Node.js, Electron gives developers access to native operating system features. These include the file system, system notifications, and much more.

Fast and Easy Development Process

Developing applications with Electron.js is quite easy, even for beginner developers. With ready-made components and libraries, you can quickly set up the basics of your application.

Develop Your First Application with Electron.js

To create an Electron application, Node.js must first be installed on your system. By following the steps below, you can develop a simple Electron application:


// Add the required libraries
const { app, BrowserWindow } = require('electron');

function createWindow() {
  // Create a new window
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true
    }
  });
  // Load your application's HTML file
  win.loadFile('index.html');
}

app.whenReady().then(createWindow);

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('activate', () => {
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow();
  }
});

The above code creates a basic Electron application and opens a window. When the window is opened, it loads the specified HTML file.

Conclusion

Electron.js is an excellent option for those who want to develop desktop applications using modern web technologies. While offering the opportunity to develop applications quickly and effectively, it also allows your users to run your apps on various operating systems with its cross-platform support. To start developing with Electron.js, you can begin with simple sample applications as shown above.