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.loadFile('index.html');
  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

👋 I'm Jim, a full-stack product engineer. Want to build an amazing product and a profitable business? Read more about me or Get in touch!

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