A node module with a few methods to easily check if you're online or a certain website is reachable.
npm i online-status-checker --save
Import the Module:
import { checkNetworkConnection, checkServerIsReachable, checkInternetConnection } from 'online-status-checker';
Check if there is a network connection - returns true or false
const result = checkNetworkConnection();
console.log(result);
Check if a specific url is alive / reachable (Status: 200) or not - returns true or false
const url = 'http://someurl.com';
const result2 = checkServerIsReachable(url);
console.log(result2);
Check if browser is online - returns true or false
const result3 = checkInternetConnection();
console.log(result3);
Angular Example:
import { Component } from '@angular/core';
import { checkNetworkConnection, checkServerIsReachable, checkInternetConnection } from 'online-status-checker';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
url = 'http://someurl.com';
result1;
result2;
result3;
constructor() {
this.result1 = checkNetworkConnection();
this.result2 = checkServerIsReachable(url);
this.result3 = checkInternetConnection();
}
}
Steven Fernandez
This project is licensed under the MIT License - see the LICENSE.md file for details
- First Commit
- Added readme with example usage
- Added example for Angular 6
- Readme Tidy
- Readme Tidy
- Code Updates