-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
v1rtl
committed
Aug 27, 2021
1 parent
3bbb1df
commit 666d5fe
Showing
2 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
# down | ||
📉 Check if website is down using `ping` command | ||
|
||
Check if website is down using `ping` command. | ||
|
||
## Example | ||
|
||
```ts | ||
import { down } from 'https://deno.land/x/down/mod.ts' | ||
|
||
await down('example.com') // false | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Check if website is down | ||
* @param host website host, e.g. example.com | ||
* @param timeout custom timeout in seconds | ||
* @returns whether website is down or not | ||
*/ | ||
export const down = async (host: string, timeout = 1): Promise<boolean> => { | ||
const cmd = Deno.run({ | ||
cmd: ['ping', `-W ${timeout}`, '-c 1', host], | ||
stdout: 'null' | ||
}) | ||
|
||
const { code } = await cmd.status() | ||
|
||
return code !== 0 | ||
} |