Node JS Script

This is a copy of the Node JS script I have on the Raspberry Pi. For the shortcut don't forget to update your RPi hostname and password.

                const args = process.argv.slice(2)
                var net = require('net');
                var Promise = require('bluebird');
                
                function checkSite(hostname, port, timeout) {
                    return new Promise(function(resolve, reject) {
                        timeout = timeout || 5000;     // default of 5 seconds
                        var timer = setTimeout(function() {
                            reject("timeout");
                            socket.end();
                        }, timeout);
                        var socket = net.createConnection(port, hostname, function() {
                            clearTimeout(timer);
                            resolve();
                            socket.end();
                        });
                        socket.on('error', function(err) {
                            clearTimeout(timer);
                            reject(err);
                        });
                    });
                }
                
                checkSite(args[0], 80).then(function() {
                    console.log('was successful');
                }, function(err) {
                    console.log('failed');
                })