Create a Notes application with Electron for Linux, MacOS and Windows

26 ago 2023 2 min di lettura
Create a Notes application with Electron for Linux, MacOS and Windows
Indice dei contenuti


Electron is a framework that allows you to create native desktop applications using web technologies such as JavaScript, HTML and CSS. In this tutorial, we'll build a simple notes application that can be used on Linux, MacOS, and Windows.


Have Node.js and npm installed. If you don't already have them, download and install from

Initial configuration

Create a new folder for your project and navigate inside:

mkdir electron-notes-app && cd electron-notes-app

Initialize a new npm project:

npm init -y

Install Electron

npm install electron --save-dev

Creation of the project structure

Create the following files and folders:

  • main.js (the main file of the Electron app)
  • index.html (the app UI)
  • styles.css (app styles)

Structuring of the user interface

In the index.html file, enter the following code:

<!DOCTYPE html>
 <title>Electron Notes App</title>
 <link rel="stylesheet" href="styles.css">
 <div class="container">
 <textarea id="noteContent"></textarea>
 <button id="saveBtn">Salva Nota</button>
 <script src="renderer.js"></script>

In styles.css, add some basic styles:

.container {
 padding: 20px;
 display: flex;
 flex-direction: column;
 height: 100vh;

 textarea {
 flex: 1;
 margin-bottom: 10px;

 button {
 align-self: flex-end;

Electron logic

In main.js, add:

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

 let win;

 function createWindow() {
 win = new BrowserWindow({
 width: 800,
 height: 600,
 webPreferences: {
 nodeIntegration: true


 app.on('window-all-closed', () => {
 if (process.platform!== 'darwin') {

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

Application logic

Create a renderer.js file and add:

const fs = require('fs');

 document.getElementById('saveBtn').addEventListener('click', () => {
 const content = document.getElementById('noteContent').value;
 fs.writeFileSync('nota.txt', content);
 alert('Nota salvata con successo!');

This code will save the contents of the textarea to a file called nota.txt each time the button is pressed.

Launch the application

In the package.json file, edit the "scripts" section to include:

"start": "electron main.js"

Now you can start the application with:

npm start


You've created a notes application with Electron that runs on Linux, MacOS, and Windows. You can further expand this app by adding features such as managing multiple notes, implementing a database, or integrating with cloud services.

Buy me a coffeeBuy me a coffee

Supportaci se ti piacciono i nostri contenuti. Grazie.

Successivamente, completa il checkout per l'accesso completo a
Bentornato! Accesso eseguito correttamente.
Ti sei abbonato con successo a
Successo! Il tuo account è completamente attivato, ora hai accesso a tutti i contenuti.
Operazione riuscita. Le tue informazioni di fatturazione sono state aggiornate.
La tua fatturazione non è stata aggiornata.