Check Internet Connection


Hey Guys.

I would make an app that loads simply to things.

If User is Online there Shows and if User are offline there loads a index.html offline file.

here is my code:

var electron = require('electron');
var app =;
var Menu = electron.Menu;
var BrowserWindow = electron.BrowserWindow;
var openAboutWindow = require('about-window').default;
var join = require('path').join;

app.once('window-all-closed',function() { app.quit(); });

app.once('ready', function() {

    const ElectronOnline = require('electron-online')
    const connection = new ElectronOnline()

    var w = new BrowserWindow({title: 'APP', center: undefined, transparent: true, width: 1024, height: 768, frame: true, resizable: false});
    w.once('closed', function() { w = null; });
    connection.on('online', () => {

    connection.on('offline', () => {

    const menu = Menu.buildFromTemplate([
            label: 'About',
            submenu: [
                    label: 'About This App',
                    click: () => openAboutWindow({
                                icon_path: join(__dirname, 'icon.png'),
                                copyright: 'Copyright',
                                open_devtools: false,

But i get some errors if i switch my internet connection.
Hope any1 can help.


I am using below code it is working fine for me.

function check_online_status() {

    if (navigator.onLine) {
        console.log('User is online  so redirect to login');
        console.log('User went to offline or no internet connection');
        alert("It seems you dont have internet connections");



navigator.onLine is useless, it only checks if you have a local connection, not whether the internet is accessible.

Use this node module to do the magic!


Thanks for the suggestion.
Will use it my project