├── .gitignore ├── .npmignore ├── README.md ├── package.json └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UpOrNot 2 | 3 | UpOrNot is a npm CLI tool for discovering whether a website is up or not. 4 | 5 | ## Installation 6 | 7 | Use the package manager [npm](https://www.npmjs.com/) to install upornot. 8 | 9 | ```bash 10 | npm install upornot 11 | ``` 12 | 13 | ## Usage 14 | Usage is simple, just run "upornot whatever.com" without the quotes to test a URL. Example: 15 | ```bash 16 | $: upornot duckduckgo.com 17 | ``` 18 | 19 | ## Contributing 20 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. 21 | 22 | ## License 23 | [ISC](https://opensource.org/licenses/ISC) -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "upornot", 3 | "version": "1.5.0", 4 | "description": "A CLI tool to test whether a website is up or not", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [ 10 | "website", 11 | "up", 12 | "down", 13 | "domain", 14 | "isitup", 15 | "reachable" 16 | ], 17 | "author": "John Paul Wile", 18 | "license": "ISC", 19 | "bin": "./index.js", 20 | "dependencies": { 21 | "arg": "^4.1.3", 22 | "inquirer": "^7.0.4", 23 | "node-fetch": "^2.6.0", 24 | "open": "^7.0.2" 25 | }, 26 | "repository": { 27 | "type": "git", 28 | "url": "https://github.com/Bots/upOrNot" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const fetch = require('node-fetch') 3 | const open = require('open') 4 | const arg = require('arg') 5 | const inquirer = require('inquirer') 6 | 7 | function ParseCliArgsIntoOptions() { 8 | const args = arg( 9 | { 10 | '--website': Boolean, 11 | '--yes': Boolean, 12 | '-w': '--website', 13 | '-y': '--yes' 14 | }, 15 | { 16 | argv: process.argv.slice(2) 17 | } 18 | ) 19 | return { 20 | website: args['--website'] || false 21 | } 22 | } 23 | 24 | async function PromptForOptions(options) { 25 | const questions = []; 26 | 27 | if (!options.website) { 28 | questions.push({ 29 | type: 'confirm', 30 | name: 'website', 31 | message: 'Open the website on your browser?', 32 | default: false, 33 | }); 34 | } 35 | 36 | const answers = await inquirer.prompt(questions); 37 | return { 38 | ...options, 39 | website: options.website || answers.website, 40 | }; 41 | } 42 | 43 | async function LaunchWebsite(result) { 44 | let options = ParseCliArgsIntoOptions(); 45 | options = await PromptForOptions(options); 46 | if (options.website == true) { 47 | open(`https://${result.domain}`); 48 | } 49 | } 50 | 51 | const site = process.argv[2] 52 | 53 | function CheckSite(name) { 54 | if (name.indexOf('.') > -1) { 55 | const info = fetch(`https://isitup.org/${name}.json`) 56 | .then(response => response.json()) 57 | 58 | info.then(function(result) { 59 | console.log(result.response_code) 60 | switch(result.response_code) { 61 | case 200: 62 | console.log('\x1b[32m%s\x1b[0m', 'website appears to be up and running') 63 | LaunchWebsite(result) 64 | break 65 | case 301: 66 | console.log('\x1b[34m%s\x1b[0m', 'website has been moved permanently but appears to be up and running') 67 | LaunchWebsite(result) 68 | break 69 | case 302: 70 | console.log('\x1b[34m%s\x1b[0m', 'website has a temporary redirect but appears to be up and running') 71 | LaunchWebsite(result) 72 | break 73 | case 403: 74 | console.log('\x1b[33m%s\x1b[0m', 'website information not found') 75 | LaunchWebsite(result) 76 | break 77 | default: 78 | console.log('\x1b[31m%s\x1b[0m', 'website appears to be down') 79 | break 80 | } 81 | }) 82 | } else { 83 | console.log('\x1b[31m%s\x1b[0m', 'please append a url extension (whatever.com)') 84 | } 85 | } 86 | 87 | CheckSite(site) --------------------------------------------------------------------------------