npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pm2wick

v1.1.6

Published

Manage your PM2 processes.

Downloads

11

Readme

PM2Wick

PM2Wick is a Node.js package designed to simplify the management of PM2 processes and unique ID generation. It provides essential utilities for interacting with PM2, making API requests, and managing configuration files with ease. This package is ideal for developers who need to automate or integrate PM2 process management in their Node.js applications.

Features

  • Unique ID Generation: Generate and store unique IDs in a file.
  • API Request Handling: Easily make HTTP requests with robust error handling.
  • Configuration Management: Read, write, and update configuration files seamlessly.
  • Customizable: Use custom file systems or configuration paths for flexibility.

Installation

To install PM2Wick, use npm:

npm install pm2wick

Usage

1. Generating a Unique ID

PM2Wick allows you to generate a unique ID that is stored in a file. If the ID already exists, it returns the existing ID.

const { createUniqueId } = require('pm2wick');

const uniqueId = createUniqueId();
console.log(`Generated Unique ID: ${uniqueId}`);

2. Making an API Request

You can make API requests with automatic error handling using the apiRequest function.

const { apiRequest } = require('pm2wick');

async function makeRequest() {
    const endpoint = 'https://api.example.com/data';
    const data = { key: 'value' };

    try {
        const response = await apiRequest(endpoint, data);
        console.log('API Response:', response);
    } catch (error) {
        console.error('API request failed:', error);
    }
}

makeRequest();

3. Managing Configuration Files

You can easily manage your configuration files by reading, writing, or updating them with the following functions:

const { getConfiguration, updateConfiguration } = require('pm2wick');

// Get the current configuration
const config = getConfiguration();
console.log('Current Configuration:', config);

// Update the configuration
updateConfiguration({ token: 'new-token', prefix: '!' });
console.log('Updated Configuration:', getConfiguration());

4. CLI Integration

PM2Wick can also be used in a CLI application to handle user inputs, manage configurations, and interact with APIs. See the CLI Example for more details.

CLI Example

You can create a simple CLI tool using PM2Wick to manage your PM2 processes or perform other tasks.

#!/usr/bin/env node

const { createUniqueId, getConfiguration, updateConfiguration, apiRequest } = require('pm2wick');
const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

function prompt(question) {
    return new Promise((resolve) => rl.question(question, resolve));
}

async function main() {
    console.log('Welcome to PM2Wick CLI');

    const config = getConfiguration();
    if (!config.id) {
        const id = createUniqueId();
        console.log(`Generated new PM2Wick ID: ${id}`);
        updateConfiguration({ id });
    } else {
        console.log(`Your existing PM2Wick ID is: ${config.id}`);
    }

    const choice = await prompt('What would you like to do? (1: Show config, 2: Update config, 3: Make API request, 4: Exit): ');

    switch (choice) {
        case '1':
            console.log('Current Configuration:', getConfiguration());
            break;
        case '2':
            const token = await prompt('Enter new token: ');
            const prefix = await prompt('Enter new prefix: ');
            updateConfiguration({ token, prefix });
            console.log('Configuration updated.');
            break;
        case '3':
            const endpoint = await prompt('Enter API endpoint: ');
            const data = JSON.parse(await prompt('Enter data as JSON: '));
            try {
                const response = await apiRequest(endpoint, data);
                console.log('API Response:', response);
            } catch (error) {
                console.error('API request failed:', error);
            }
            break;
        case '4':
            console.log('Exiting...');
            rl.close();
            return;
        default:
            console.log('Invalid choice. Exiting...');
            rl.close();
            return;
    }

    rl.close();
}

main().catch(err => {
    console.error('An error occurred:', err);
    rl.close();
});

Testing

PM2Wick includes a comprehensive test suite. To run the tests, simply use:

npm test

Tests are written using Jest and cover all key functionalities, including unique ID generation, API requests, and configuration management.

Contributing

Contributions are welcome! Please submit an issue or a pull request on GitHub if you have suggestions or improvements.

License

PM2Wick is licensed under the MIT License. See the LICENSE file for more details.

Support

For support, join our Discord server.


Developed with ❤️ by Wick Studio.