Skip to content

ronnytomasetti/bt-find-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Find Server function.

Installation

$ npm install bt-find-server

or alternatively using Yarn package manager

$ yarn add bt-find-server

Usage

// Require bt-find-server module as findServer.
var findServer = require('bt-find-server');

// Setup server array.
// Must be an array of objects containing url and priority values.
var serverArray = [{
	"url": "http://doesNotExist.boldtech.co",
	"priority": 1
}, {
	"url": "http://boldtech.co",
	"priority": 7
}, {
	"url": "http://offline.boldtech.co",
	"priority": 2
}, {
	"url": "http://npmjs.com",
	"priority": 4
}];

// Call findServer() function passing in serverArray
findServer(serverArray).then(function(results) {
	// If successful, results will be an object containing:
	// { url: 'http://npmjs.com', priority: 4, statusCode: 200 }
}).catch(function(error) {
	// If unsuccessful, error contains message:
	  // Failed, all servers offline - If no servers responded with valid status code.
	  // Invalid server array - If no valid urls/priority values were provided.
	  // Fatal error, findserver() failed with message: \n + error.message
});

Options

under construction

Testing

$ npm install
$ npm test

License

ISC

About

Determine availability of given list of servers and returns an available server with the lowest priority number.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published