Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More β†’
Socket
Sign inDemoInstall
Socket

electron

Package Overview
Dependencies
Maintainers
2
Versions
1335
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron

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

  • 34.0.0-alpha.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
599K
decreased by-24.66%
Maintainers
2
Weekly downloads
Β 
Created

What is electron?

Electron is a framework for creating native applications with web technologies like JavaScript, HTML, and CSS. It combines the Chromium rendering engine and the Node.js runtime, allowing you to build cross-platform desktop applications.

What are electron's main functionalities?

Creating a Browser Window

This feature allows you to create a new browser window in your Electron application. The code sample demonstrates how to create a window and load a URL into it.

const { app, BrowserWindow } = require('electron');

app.on('ready', () => {
  const mainWindow = new BrowserWindow({ width: 800, height: 600 });
  mainWindow.loadURL('https://example.com');
});

Inter-Process Communication (IPC)

Electron provides IPC (Inter-Process Communication) to allow communication between the main process and renderer processes. The code sample shows how to send and receive messages asynchronously.

const { ipcMain, ipcRenderer } = require('electron');

// Main process
ipcMain.on('asynchronous-message', (event, arg) => {
  console.log(arg); // prints 'ping'
  event.reply('asynchronous-reply', 'pong');
});

// Renderer process
ipcRenderer.send('asynchronous-message', 'ping');
ipcRenderer.on('asynchronous-reply', (event, arg) => {
  console.log(arg); // prints 'pong'
});

Using Node.js Modules

Electron allows you to use Node.js modules in your application. The code sample demonstrates how to use the 'fs' module to read a file.

const fs = require('fs');

fs.readFile('/path/to/file', (err, data) => {
  if (err) throw err;
  console.log(data.toString());
});

Packaging the Application

Electron applications can be packaged for distribution using tools like 'electron-packager'. The code sample shows how to package an Electron app for Windows using a child process.

const { exec } = require('child_process');

exec('electron-packager . myApp --platform=win32 --arch=x64', (err, stdout, stderr) => {
  if (err) {
    console.error(`exec error: ${err}`);
    return;
  }
  console.log(`stdout: ${stdout}`);
  console.error(`stderr: ${stderr}`);
});

Other packages similar to electron

Keywords

FAQs

Package last updated on 28 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc