1.0.4 • Published 8 months ago

serverchecker v1.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

Server Checker Tool

The main purpose of this repository is to create a node module that can assess a list of webservers and then returns a server with the lowest priority. Also create a unit test that can check if the function is running properly.

Pre-requisites

  • Install Node.js version 18.18.0 LTS or higher
    or
  • Using nvm
nvm install --lts
nvm use --lts

Getting started

  • Clone the repository
git clone https://github.com/hakusenk24/scentro-serverchecker.git
  • Install dependencies
cd scentro-serverchecker
npm install
  • Run unit tests
npm run test

Using with demo

Note: Must require Nodejs v18.18.0 or higher

  • There are 2 mono repos inside this project to help you try this tool.
Try demo with javascript
  • Go to demo/js folder
cd ./demo/js
  • Use required Nodejs version
nvm use --lts
  • Install dependencies
npm install
  • Run index file
node index.js
Try demo with typescript
  • Go to demo/typescript folder
cd ./demo/typescript
  • Use required Nodejs version
nvm use --lts
  • Install dependencies
npm install
  • Build index.ts to index.js
npx tsc index.ts
  • Run index file
node index.js

Using for external project

Note: Must require Nodejs v18.18.0 or higher

  • Install packages
npm install serverchecker
  • Use with Typescript
import ServerChecker from "serverchecker";

const input = [
  {
    "url": "https://does-not-work.perfume.new",
    "priority": 1
  },
  {
    "url": "https://gitlab.com",
    "priority": 4
  },
  {
    "url": "http://app.scnt.me",
    "priority": 3
  },
  {
    "url": "https://offline.scentronix.com",
    "priority": 2
  }
];

// timeout after 5 seconds as default
const servChecker = new ServerChecker(input);

servChecker.findServer()
  .then((result: any) => console.log(result))
  .catch((e: any) => console.log(e))


// timeout after 10 seconds by passing timeout option
const servChecker_2 = new ServerChecker(input, {
  timeout: 10000
});

servChecker_2.findServer()
  .then((result: any) => console.log(result))
  .catch((e: any) => console.log(e))
  • Use with Javascript
const ServerChecker = require('serverchecker').default;

const input = [
  {
    "url": "https://does-not-work.perfume.new",
    "priority": 1
  },
  {
    "url": "https://gitlab.com",
    "priority": 4
  },
  {
    "url": "http://app.scnt.me",
    "priority": 3
  },
  {
    "url": "https://offline.scentronix.com",
    "priority": 2
  }
];

// timeout after 5 seconds as default
const servChecker = new ServerChecker(input);

servChecker.findServer()
  .then(result => console.log(result))
  .catch(e => console.log(e))


// timeout after 10 seconds by passing timeout option
const servChecker_2 = new ServerChecker(input, {
  timeout: 10000
});

servChecker_2.findServer()
  .then(result => console.log(result))
  .catch(e => console.log(e))

Dependencies and libraries

  • Typescript
  • Fetch API: Built-in Javascript to make HTTP requests, remember to use Nodejs v18.18.0 or higher
  • Jest: Delightful JavaScript testing framework
  • Yup: Schema builder, interdependent validations

Project Structure

The folder structure of this app is explained below:

NameDescription
distContains the distributable (or output) from your TypeScript build.
node_modulesContains all npm dependencies
libImportant modules used in this tool
lib/serverchecker.tsMain module to handle all logics
lib/fetcher.tsModule used to fetch resources, including timeout request fetching
lib/validator.tsContains some utility functions
testContains all unit tests
index.tsindex file
package.jsonContains npm dependencies and scripts
jest.config.jsonConfig settings for Jest
tsconfig.jsonConfig settings for Typescript

Npm Script

Npm ScriptDescription
buildTypeScript build
testRun unit tests using Jest
1.0.4

8 months ago

1.0.3

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago