diff --git a/README.md b/README.md index 62cb70e..414dc32 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/mod.ts b/mod.ts new file mode 100644 index 0000000..956dec9 --- /dev/null +++ b/mod.ts @@ -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 => { + const cmd = Deno.run({ + cmd: ['ping', `-W ${timeout}`, '-c 1', host], + stdout: 'null' + }) + + const { code } = await cmd.status() + + return code !== 0 +}