1.0.4 • Published 8 months ago
serverchecker v1.0.4
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
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:
Name | Description |
---|---|
dist | Contains the distributable (or output) from your TypeScript build. |
node_modules | Contains all npm dependencies |
lib | Important modules used in this tool |
lib/serverchecker.ts | Main module to handle all logics |
lib/fetcher.ts | Module used to fetch resources, including timeout request fetching |
lib/validator.ts | Contains some utility functions |
test | Contains all unit tests |
index.ts | index file |
package.json | Contains npm dependencies and scripts |
jest.config.json | Config settings for Jest |
tsconfig.json | Config settings for Typescript |
Npm Script
Npm Script | Description |
---|---|
build | TypeScript build |
test | Run unit tests using Jest |