Skip to content

Level/electron-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

electron-demo

Demo app loading LevelDB into an Electron context.

level badge Test Standard Donate

Get started

git clone https://github.com/Level/electron-demo.git
cd electron-demo
npm install
npm start

You're now ready to use LevelDB. Try running await db.put('key', 2) in the devtools console of the Electron window, followed by await db.get('key')!

Architecture

The main process (main.js) opens a LevelDB database using level and exposes it to renderer processes (renderer.js) using many-level. The processes communicate using Electron IPC. This approach is a secure default that allows renderer processes to be sandboxed. As a consequence, require() is not available, so we use browserify to bundle the JavaScript into a single file.

Alternatively you can enable the potentially insecure nodeIntegration option and do the following in a renderer process:

const { Level } = require('level')
const db = new Level('./db')

But then only one process can open the database at the same time. Another alternative is to use browser-level in renderer processes, if you want each process to have its own database backed by IndexedDB.

As this is a demo, the implementation here (specifically the IPC) is not optimized and does not handle errors. The demo also does not include scripts to package up the Electron app for production (e.g. using electron-builder) which will require a few additional steps (e.g. asarUnpack in the case of electron-builder) due to the use of Node.js native addons.

Contributing

Level/electron-demo is an OPEN Open Source Project. This means that:

Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.

See the Contribution Guide for more details.

Donate

Support us with a monthly donation on Open Collective and help us continue our work.

License

MIT