Getting Started with Electron: Building Desktop Apps for Web Developers

Your First Electron App: A Minimal Example

Section 3

Chapter 1: Welcome to the Desktop: Your First Electron App

Getting Started with Electron: Building Desktop Apps for Web DevelopersChapter 1: Welcome to the Desktop: Your First Electron App

Welcome to the exciting world of desktop application development with Electron! As a web developer, you already possess many of the skills needed to build powerful, cross-platform desktop applications. Electron bridges the gap between web technologies and native desktop experiences, allowing you to leverage your existing knowledge of HTML, CSS, and JavaScript to create amazing apps. In this section, we'll guide you through building your very first Electron application – a minimal example that demonstrates the fundamental components.

Before we dive into code, let's understand what makes an Electron app tick. At its core, an Electron app is a standard Node.js application that leverages Chrome's rendering engine (Chromium) to display a web page. This web page isn't just any web page; it's your application's user interface, rendered in a dedicated window.

Let's get started by setting up a new project. First, create a new directory for your project. You can name it anything you like, but 'my-first-electron-app' is a good choice for now.

mkdir my-first-electron-app
cd my-first-electron-app

Next, we need to initialize a new Node.js project within this directory. This will create a package.json file, which is crucial for managing your project's dependencies and defining how your app runs.

npm init -y

The -y flag tells npm to accept all the default options, which is perfect for our minimal example. Now, we need to install Electron as a development dependency. This means Electron will be available when you're developing your app, but it won't be bundled with your final application unless you explicitly configure it to be.

npm install --save-dev electron
チャプターへ戻る