English | 中文简体
- Check the url is normally accessible or not.
- Check url network latency.
![]() IE / Edge |
![]() Firefox |
![]() Chrome |
![]() Safari |
![]() Opera |
|---|---|---|---|---|
| IE9, IE10, IE11, Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
Using npm, download and install the code.
npm install --save ping-urlFor node environment:
var base = require('ping-url');For webpack or similar environment:
import base from 'ping-url';For requirejs environment:
requirejs(['node_modules/ping-url/dist/ping-url.cjs.js'], function (base) {
// do something...
})For browser environment:
<script src="node_modules/ping-url/dist/iping-url.min.js"></script>Customize the protocol name
The default protocol for Ping is http. If customization is required, use this method to set it up before use.
- param {object} option
- option.protocol {string} protocol
values:['http', 'https']
- option.protocol {string} protocol
- return {string} The protocol name of the final setting
import Ping from 'ping-url';
Ping.config({
protocol: 'https'
});Checks the availability of the url and returns the check information.
Check its accessibility and network latency by requesting the url.
- param {string} url the url to detect
- return {object} return
Promiseobject- response(resolve status)
- response.status {boolean}
true: Can be accessedfalse: Can not be accessed - response.time {number} Network delay (millisecond), when inaccessible, the default is' -1 '
- response.status {boolean}
- response(reject status)
- response.status {boolean}
false: Can not be accessed - response.msg {string} Error message
- response.status {boolean}
- response(resolve status)
import Ping from 'ping-url';
Ping.check('https://wangxiaokai.vip').then(res => {
console.log(`status: ${res.status} and time: ${res.time}`);
}, res => {
console.log(`error msg: ${res.msg}`);
});MIT




