Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

How to start to make your first Electron js app

Posted on May 23, 2021May 23, 2021 by Habibie

Let’s go to the point. First of all you must download and install NodeJS. After it’s installed, you’re ready to start to make new project.

Open your Command Prompt, in Windows for example. Go to any folder/directory. Make new folder for your project, and go inside it. Then run this command:

npm init -y

Then

npm i –save-dev electron

Edit your auto generated package.json file to be look like this:

{
  "name": "tinyhtmlwriter",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": {
    "start": "electron ."
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "electron": "^12.0.9"
  }
}

Then make an index.html file, simply like this:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>New Project</title>
	</head>
	
	<body>
		<p>Hello world!</p>
	</body>
</html>

Then make main.js file like this one:

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

function createWindow () {
	const win = new BrowserWindow({
		width: 1280,
		height: 720,
		webPreferences: {
			nodeIntegration: true,
			enableRemoteModule: true,
		}
	})

	win.loadFile('index.html')
	win.webContents.openDevTools();
	
}

app.whenReady().then(createWindow)

app.on('window-all-closed', () => {
	app.quit();
});

app.on('activate', () => {
	if (BrowserWindow.getAllWindows().length === 0) {
		createWindow()
	}
})

ipcMain.on('quitprogram', (evt, arg) => {
	app.quit();
});

That’s all. You’ve generated your new project files. To start the program, type this command in your Command Prompt:

npm start

To build your program as Windows executable, check out this post: https://thirteenov.ciihuy.com/how-to-build-your-electron-js-app-as-windows-executable-for-windows/

To build it for Mac, check out this post: https://thirteenov.ciihuy.com/how-to-build-your-electron-js-for-mac/

Post Views: 411
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Hover Reveal script for Unity to show and hide object on mouse hover
  • How to Prevent UI Clicks in Unity from “Bleeding Through” to 3D Objects Behind Them
  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
© 2026 ThirteeNov | Powered by Superbs Personal Blog theme