Get the root path of an Electron application.

Ganesh Rathinavel
1 min readFeb 5, 2019

--

Introduction

Get the root path of an Electron application.

Finding the root path of an electron app could become tricky, this NPM package helps you with the same

Initially, I created the “electron-root-path” NPM package as an internal utility for OpenMTP — Advanced Android File Transfer Application for macOS. It works well with the Electron React Redux Advanced Boilerplate and electron-react-boilerplate.

Installation

$ npm install electron-root-pathor $ yarn add electron-root-path

Usage

// Import ES6 way
import { rootPath } from 'electron-root-path';
// Import ES2015 way
const rootPath = require('electron-root-path').rootPath;
// e.g:
// read a file in the root
const location = path.join(rootPath, 'package.json');
const pkgInfo = fs.readFileSync(location, { encoding: 'utf8' });
  • After packaging the app, the rootPath will point to the absolute directory path of <APP_PACKAGE_NAME>.app
// eg: /Applications/AppName.app
  • Handle the packaged condition using:
const isProd = process.env.NODE_ENV === 'production';// orconst isPackaged = process.mainModule.filename.indexOf('app.asar') !== -1;

Contacts

Please feel free to contact me at ganeshrvel@outlook.com

More repos

License

electron-root-path | Get the root path of an Electron Application is released under MIT License.

Copyright © 2018-Present Ganesh Rathinavel

--

--