The shell module provides functionalities that are related to the native desktop integrations. You can use this module to manage the files and URLs using the default application. For example, if you want to open a file using its default application, you can use this module. You can also open the URL in the default browser. This gives a deep integration with the operating system. The API is available both in the main process and the renderer process.
For example, you can open a file in native file explorer using the showItemInFolder
method of the shell:
const { shell } = require('electron'); // Open the file explorer shell.showItemInFolder('/Users/Guest/Downloads');
This opens the Downloads
folder inside the file explorer or finder on Mac. To open a file with the default application that your file is associated with, you can use openItem
method of the shell:
shell.openItem('/Users/Guest/Downloads/file.txt');
To open a link in the system default browser, use the openExternal...