How to Create Desktop App With JavaScript & Electron

In this lesson we want to learn How to Create Desktop App With JavaScript & Electron, so first of all let’s talk about ElectronJS.

 

 

What is ElectronJS?

ElectronJS is a framework that allows developers to build cross platform desktop applications using web technologies such as JavaScript, HTML and CSS. it is built on top of Chromium, the open source version of Google Chrome and Node.js, which provides runtime environment for JavaScript. with ElectronJS developers can use the same codebase to create applications for Windows, Mac and Linux. One of the main benefits of ElectronJS is that it allows you to use their existing web development skills to create desktop applications. Developers can use popular web frameworks such as React, Angular or Vue.js to build the user interface and Node.js to handle the backend logic.

 

 

Structure of ElectronJS

Structure of an ElectronJS application is composed of two main parts: main process, which runs on the desktop and manages the application’s lifecycle, and renderer process, which runs in a web page and handles the user interface. main process and the renderer process communicate with each other through inter process communication (IPC) mechanisms.

 

 

What Applications are Created with ElectronJs?

ElectronJS is used by many popular applications such as Visual Studio Code, Slack and Discord. it is also good for creating desktop applications that require offline capabilities, native system integration or access to hardware devices.

 

 

How to Create Desktop App With JavaScript & Electron

This is basic example of how to create a desktop app with JavaScript and Electron:

  1. First, you need to install Electron by running the following command in your terminal: npm install electron
  2. After that navigate to an Empty Directory to setup the project and run the following command npm init, this command generate the package.json file.
  3.  In this directory create new file called main.js and another called index.html.
  4. In your main.js file, you will need to set up your Electron app by importing electron module and creating new BrowserWindow object. Your code should look something like this:

 

  1. In your index.html file you can set up the UI for your app using HTML and CSS. This is where you will add any buttons, text fields or other elements that you want to include in your app.
  2. To run your app, you can use the command electron . in your terminal. this will launch your app in new window.
  3. You can also build and package your app for distribution on different platforms, such as Windows, Mac or Linux.

 

 

This is just basic example and you can add more functionality and features to your app as you continue to develop it.

 

Also to run your application make sure that add this in your package.json file.

 

 

 

This will be our package.json file, also you can see our main file name is main.js, if you have index.js, then you need to change that.

 

 

 

 

Run the code with npm start and this will be result.

How to Create Desktop App With JavaScript & Electron
How to Create Desktop App With JavaScript & Electron

 

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Leave a Comment

Share via
Copy link
Powered by Social Snap
×