Create your app

To begin, we will set up a base electron app using an npm package called electron-forge.

Note: Electron Forge isn’t the only way to get started with Electron! There are other resources, like Electron Quick Start.

To get started, we need to go through a few steps.

gif of following the directions below

  1. Find the terminal and navigate to your desired project location, for example: cd ~/ will navigate to your home directory.
  2. Install electron-forge globally: npm install -g electron-forge
  3. Initialize a new project: electron-forge init electron-app
  4. Change into that app’s directory: cd electron-app

Important files to watch out for in any Electron app:

  • package.json
  • package-lock.json
  • src/index.html
  • src/index.js
Tell me why

Any Electron app has 2 types of processes that interact with each other. The main process, initialized by package.json, and a renderer process generated by each web page.

  • package.json - Points to the app’s main file and lists your project’s details and dependencies.
  • package-lock.json - If you’re using NPM 5 or greater (you can check by running npm -v), you’ll also get a package-lock.json file. This file aims to keep versions of dependencies identical across projects.
  • src/index.html - A web page to render. Each web page will spin off its own renderer process.
  • src/index.js - The default script called by package.json to create windows and handle system events. Runs the app’s main process.

What is Node?

Node.js is the server side portion of full stack Javascript. Many websites are powered with Node, and it powers things on Electron as well. Node.js documentation is full of information that explain its functionality and purpose.

What is npm?

npm, short for “Node Package Manager”, is exactly as it is named: a manager for packages in Node. Dependencies and their versions are managed in apps through the package.json file, and downloaded through npm.

Stuck? Open an issue in the repository for this class and mention @githubteacher for help from one of the GitHub trainers!
Continue