Last active
May 8, 2024 10:55
-
-
Save sharafdin/2c90458a9550b98ae3f97a496cca55ad to your computer and use it in GitHub Desktop.
π Instantly amplify your npm package's downloads with npm Downloads Increaser! This powerful script rapidly boosts your download stats, showcasing your package's popularity. Dive in and see your numbers soar! π
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import https from 'https'; // Import the https module to make HTTPS requests | |
import readline from 'readline'; // Import the readline module for interactive command line interfaces | |
// Create a readline interface for user input from the command line | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
/** | |
* Asks a user-defined question and returns a promise with the answer. | |
* @param {string} question - Question to be asked to the user. | |
* @return {Promise<string>} A promise that resolves with the user's answer. | |
*/ | |
function askQuestion(question) { | |
return new Promise((resolve) => { | |
rl.question(question, (answer) => { | |
resolve(answer); // Resolve the promise with the answer | |
}); | |
}); | |
} | |
/** | |
* Simulates downloads for a specified npm package by repeatedly making HTTP GET requests. | |
* The function queries the user for the package name, version, and the desired number of simulated downloads. | |
* @param {number} intervalTime - Interval in milliseconds between each simulated download request. | |
* Default is set to 5000 milliseconds (5 seconds). | |
*/ | |
async function simulateDownloads(intervalTime = 5000) { // Default interval set to 5 seconds | |
const packageName = await askQuestion('Enter the package name: '); // Get package name from user | |
const version = await askQuestion('Enter the package version: '); // Get package version from user | |
const downloadTarget = await askQuestion('How many downloads do you need? '); // Get target download count | |
// Construct the URL to fetch the package from npm registry | |
const url = `https://registry.npmjs.org/${packageName}/-/${packageName}-${version}.tgz`; | |
let downloadCount = 0; // Counter for the number of downloads | |
// Set up a repeating interval to simulate downloads | |
const interval = setInterval(() => { | |
https.get(url, (res) => { // Make a GET request to the npm package URL | |
if (res.statusCode === 200) { | |
downloadCount++; // Increment the download count on successful response | |
console.log(`Download count: ${downloadCount}`); // Log the current download count | |
} else { | |
console.error('Failed to download with status code:', res.statusCode); // Log errors for unsuccessful attempts | |
} | |
// Check if the download count has reached the user's target | |
if (downloadCount >= parseInt(downloadTarget)) { | |
clearInterval(interval); // Stop the interval | |
console.log('Target downloads reached.'); // Log that the target has been reached | |
rl.close(); // Close the readline interface | |
} | |
}).on('error', (error) => { // Handle network errors | |
console.error('Error fetching URL:', error); // Log any errors encountered during the request | |
clearInterval(interval); // Stop the interval on error | |
rl.close(); // Close the readline interface | |
}); | |
}, intervalTime); // Use the intervalTime variable for setting the interval | |
} | |
simulateDownloads(); // Call the function to start the download simulation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
npm Downloads Increaser
Overview
The
npm Downloads Increaser
is a Node.js script designed to simulate increased download counts for npm packages. This script makes repeated HTTP GET requests to a specified npm package URL, mimicking downloads to artificially boost the package's download statistics. It's primarily intended to showcase the package's potential popularity.Prerequisites
Setup
git clone https://gist.github.com/isasharafdin/2c90458a9550b98ae3f97a496cca55ad npm-downloads-increaser cd npm-downloads-increaser
package name
. Type the name of the npm package you wish to increase downloads for and press Enter.package version
. Enter the version number of the package and press Enter.number of downloads you need
. Enter the desired number of simulated downloads and press Enter.The script will start making requests to the npm registry, simulating downloads. You'll see the download count increase in real-time until it reaches your specified target.
Modifying the Download Interval
The default interval for simulated downloads in the
npm Downloads Increaser
script is set to 5 seconds. This interval can be adjusted to fit different testing scenarios or network capacities.How to Adjust the Interval
Find where the
simulateDownloads
function is called in the script:Pass a new interval time (in milliseconds) as an argument to modify the frequency of downloads:
For a 10-second interval:
For a 1-second interval:
Considerations
Adjust the interval to meet your specific requirements, whether for intense load testing or for more conservative network usage.
Note
This tool is meant for educational purposes or to test your npm package's response under higher traffic conditions. Please use it responsibly and ethically, respecting npm's terms of service and community standards.