Check if code is running in Electron renderer process
Switch branches/tags
Nothing to show
Clone or download
jprichardson Merge pull request #7 from petetnt/patch-1
Remove the mention of one line module from the
Latest commit 48b6c47 Jun 29, 2018
Failed to load latest commit information.
.gitignore initial commit Jul 4, 2015 2.0.1 Sep 25, 2016
index.js Remove trailing spaces Sep 25, 2016
package.json 2.0.1 Sep 25, 2016 Update Jun 29, 2018
test.js initial commit Jul 4, 2015


Check if code is running in Electron renderer process.


Electron code can run in either the main process or the renderer process. This is the same as asking if the code is running in a web page with access to the DOM or not. Read more here:

Use Cases:

  • Creating a single module that acts differently whether it's running in main or renderer.
  • Logging utility. One process (main) would be responsible for writing to log files, while renderers would send log data to the main. Would allow your code to have one log method.
  • Testing. Your test code may behave differently if the DOM is available.
  • Normalize console.log behavior. console.log behavior is weird in renderer, this can easily be fixed.


npm i --save is-electron-renderer


You'll notice that when using console.log in Electron that in the renderer process outputs some weird log level garbage to stderr before your actual console message. You can normalize this behavior:


// clean up Electron output
function hook () {
  var isRenderer = require('is-electron-renderer')
  var pre = '(' + (isRenderer ? 'RENDERER' : 'MAIN') + ') '
  console.log = function (msg) {
    process.stdout.write(pre + msg + '\n')

module.exports = {
  hook: hook



output (main):

(MAIN) hello

output (renderer):

(RENDERER) hello


var isRenderer = require('is-electron-renderer')
// => (BOOLEAN)



Copyright 2015 JP Richardson