Gathering detailed insights and metrics for nginx-upstream
Gathering detailed insights and metrics for nginx-upstream
npm install nginx-upstream
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
2,993
Last Day
1
Last Week
5
Last Month
20
Last Year
206
6 Stars
63 Commits
4 Forks
4 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
0.1.4
Package Id
nginx-upstream@0.1.4
Size
7.62 kB
NPM Version
4.4.1
Node Version
4.5.0
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-50%
5
Compared to previous week
Last month
0%
20
Compared to previous month
Last year
-37%
206
Compared to previous year
Currently it is on release v0.1.3 and maintains primary functionality over nginx config file. Usage is pretty simple, you can use it with require to get our main class and use its instance with below constructor parameters.
1npm install nginx-upstream --save
1var NginxManager = require('nginx-upstream'); 2var nginxManager = new NginxManager('<path>/nginx.conf', 50);
First of all, let's take a look at the type definition of the package starting from constructor.
1class NginxUpstream { 2 constructor(nginxConfigFilePath: string, fileSyncTime?: number);
As expected our class initializes with the nginx config file path as first parameter. Second parameter is the timeout for waiting changes on config file. Default is 50ms and it is generally ok for nowadays disks.
Nginx requires upstream block for load balancing operations. You can add new backend to your upstream block by addBackend method. Below is the definition of it;
1addBackend(host: string, callback: (err: any) => void);
addBackend method requires the host definition together with the port where the backend application server exits. This host definition can be either like ip:port or like fqdn:port. ie. 123.45.67.89:80 or www.example.com:81
Here port definition is always required even if your backend server is a web server and by default hosts over 80 port, you need to mention this to your Nginx server and our method also requires this port information to set nginx configuration file correctly.
Second parameter is callback, where you need to provide to understand if the configuration set successfully or not. Usage example;
1nginxManager.addBackend('mybackendserver.io:8081', function(err){ 2 if(err){ 3 console.log(err); 4 return; 5 } else { 6 // Do something after backend server added. 7 } 8});
Another method is of nginx-upstream is toggleBackend, which is for enabling or disabling your backend server. This is realy useful when you want to make maintenance on one of your backend server or something is wrong with it and you want it to be disabled temporarily. Even if you want to remove your backend server than it is wise to disable it first and than remove it.
Below is the definition and usage of toggleBackend;
1// Definition
2toggleBackend(host: string, callback: (err: any, status: boolean) => void);
3
4// Usage
5nginxManager.toggleBackend('localhost:81', function(err, status){
6 if(err){
7 console.log(err);
8 return;
9 } else if(status)
10 // Do something if status enabled.
11 } else {
12 // Do something else if status disabled.
13 }
14});
It is like add backend and it requires the host name together with its port. When you toggle your backend host "localhost:81" of this configuration.
1# Upstream Servers 2upstream nginxconf { 3 server localhost:81; 4 server localhost:82; 5}
the nginx configuration file would be like below;
1# Upstream Servers 2upstream nginxconf { 3 server localhost:81 down; # Disabled backend 4 server localhost:82; 5}
Ofcourse we have another method for removing the backend server from the nginx configuration file. It goes like below for the same upstream block;
1// Definition 2removeBackend(host: string, callback: (err: any) => void); 3// Usage 4nginxManager.removeBackend('localhost:81', function(err){ 5 if(err){ 6 console.log(err); 7 return; 8 } else 9 // Do something after backend server removed. 10});
After calling the removeBackend method, upstream block would be;
1# Upstream Servers 2upstream nginxconf { 3 server localhost:82; 4}
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
38 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More