Socket
Socket
Sign inDemoInstall

electron

Package Overview
Dependencies
1
Maintainers
1
Versions
1268
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    electron

Event-based tiny CLI famework.


Version published
Weekly downloads
667K
decreased by-0.32%
Maintainers
1
Install size
60.8 kB
Created
Weekly downloads
 

Package description

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

Readme

Source

electron

Event based CLI framework.

FAQs

Last updated on 18 May 2012

Did you know?

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc