Skip to content

Commit

Permalink
write the module
Browse files Browse the repository at this point in the history
  • Loading branch information
v1rtl committed Aug 27, 2021
1 parent 3bbb1df commit 666d5fe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
11 changes: 10 additions & 1 deletion README.md
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
```
16 changes: 16 additions & 0 deletions mod.ts
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
}

0 comments on commit 666d5fe

Please sign in to comment.