Program, który przykładowo pokazuje zasadę działania biblioteki electron w node.js
plik main.js
const electron = require('electron') const {app, BrowserWindow} = require('electron') const path = require('path') const url = require('url') function createWindow () { // Create the browser window. win = new BrowserWindow({ width: 800, height: 600, }) win.setBackgroundColor('#ff00a3'); // zmiana tła win.setMenu(null);//usuniecie paska menu // and load the index.html of the app. win.loadURL(url.format({ pathname: path.join(__dirname, 'index.html'), protocol: 'file:', slashes: true })) } app.on('ready', createWindow)
plik index.html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Hello World!</title> </head> <body> <button id="btn" type="button">Set</button> <script src="render.js"></script> </body> </html>
plik render.js
const btn = document.getElementById('btn'); btn.addEventListener('click', function handleClick() { btn.textContent = 'Button clicked'; });