Electron hello world

First, install Electron via NPM:

$ npm init -y
$ npm install --save electron

Then create a web page to display in index.html:

<!DOCTYPE html><html><body>Hello World!</body></html>

Then create main.js, your app’s entry point, which loads that web page in an Electron window:

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

// Keep a global reference.
// A windows is closed when its object is GC'd!
let mainWindow;

app.on('ready', () => {
  mainWindow = new BrowserWindow({});
  mainWindow.on('closed', () => app.quit());

Finally, run your app with the electron binary:

$ ./node_modules/.bin/electron .

If all goes well, you’ll get a new window which says “Hello world!”.

Tagged #programming.

Similar posts

More by Jim

Want to build a fantastic product using LLMs? I work at Granola where we're building the future IDE for knowledge work. Come and work with us! Read more or get in touch!

This page copyright James Fisher 2019. Content is not associated with my employer. Found an error? Edit this page.