Skip to content

Instantly share code, notes, and snippets.

@sharafdin
Last active May 8, 2024 10:55
Show Gist options
  • Save sharafdin/2c90458a9550b98ae3f97a496cca55ad to your computer and use it in GitHub Desktop.
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! 🌟
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
@sharafdin
Copy link
Author

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

  • Node.js installed on your machine.
  • Basic familiarity with the command line interface.

Setup

  1. Clone the Gist/Repository: First, ensure that you have the script on your local machine. You can clone it from its GitHub Gist or repository.
    git clone https://gist.github.com/isasharafdin/2c90458a9550b98ae3f97a496cca55ad npm-downloads-increaser
    cd npm-downloads-increaser
  2. Install Node.js: If not already installed, download and install Node.js from nodejs.org.
  3. Running the Script
    1. Open your terminal/command prompt.
    2. Navigate to the directory containing the script.
    3. Run the script using Node.js:
      node npm-downloads-increaser.js
  4. Follow the on-screen prompts:
  • The script will first ask you to enter the package name. Type the name of the npm package you wish to increase downloads for and press Enter.

name

  • Next, it will ask for the package version. Enter the version number of the package and press Enter.

version

  • Finally, it will ask for the number of downloads you need. Enter the desired number of simulated downloads and press Enter.

downloads

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

  1. Locate the Function Call:
    Find where the simulateDownloads function is called in the script:
    simulateDownloads(); // Default call with 5 seconds interval
  2. Change the Interval:

Pass a new interval time (in milliseconds) as an argument to modify the frequency of downloads:

  • For a 10-second interval:

        simulateDownloads(10000);
  • For a 1-second interval:

    simulateDownloads(1000);

Considerations

  • Network Load: Be cautious of setting the interval too short as it may overwhelm your network, especially with larger packages.
  • Testing Realism: Longer intervals may better simulate real-world download patterns and help ensure your network's stability during tests.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment