title: Cannot read property 'on' of undefined in electron javascript
body: <p>I am trying to run this code but every time I am getting this error message. First I installed <code>npm</code> globally. Then I installed it within my app but still getting same error.</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'on' of undefined at
    Object. (H:\electric\main.js:12:4) at Object.
    (H:\electric\main.js:63:3) at Module._compile (module.js:571:32) at
    Object.Module._extensions..js (module.js:580:10) at Module.load
    (module.js:488:32) at tryModuleLoad (module.js:447:12) at
    Function.Module._load (module.js:439:3) at Module.require
    (module.js:498:17) at require (internal/module.js:20:19) at
    file:///H:/electric/views/login.html:2:3</p>
  </blockquote>
  
  <pre><code>const electron = require('electron');
  const {Menu} = require('electron');
  const {app} = require('electron');
  const {BrowserWindow} = require('electron');
  const conn = require('mysql');
  const path = require('path');
  const url = require('url');
  
  // const app = electron.app;
  // const BrowserWindow = electron.BrowserWindow;
  var mainWindow = null;
  app.on('ready', function () {
      mainWindow = new BrowserWindow({ width: 1024, height: 768, backgroundcolor: '#2e2c29' });
      mainWindow.loadURL(url.format({
          pathname: 'popupcheck.html',
          protocol: 'file:',
          slashes: true
      }));enter code here
      mainWindow.webContents.openDevTools();
      mainWindow.setProgressBar(1);
  });`][1]
  </code></pre>