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

moonito

v1.7.0

Published

Moonito is a simple but powerful real-time web traffic filtering service and analytics that not only helps you to track, analyse and understand your visitors but also protects your website from bot attacks, data scraping, and other unwanted activities.

Downloads

80

Readme

Moonito - Website Security, Traffic Filtering and Analytics Made Easy

Moonito is a Node.js and TypeScript module built for web protection, traffic filtering, and analytics. It safeguards your application by detecting and blocking potentially harmful traffic based on IP, user agents, and visitor behavior. With Moonito, you can shield your website from bots, competitors, and unwanted traffic, all while gaining actionable insights into your audience.

To use Moonito, you need an API key and a subscription to the Moonito service. For more details, review our Moonito documentation.

Installation

Install Moonito using npm:

npm install moonito

Usage

Method 1: Using Express Middleware

import express from 'express';
import { VisitorTrafficFiltering } from 'moonito';

// Create an Express application
const app = express();
const port = 3000;

/**
 * Configuration object for VisitorTrafficFiltering
 * This configuration is used to set up the AnalyticsHandler instance for handling visitor requests.
 * To use the API, you need to set up your public and secret API keys.
 *
 * Visit https://moonito.net/api for more details.
 */
const config = {
    isProtected: true, // Enable protection for the site (true) or disable it (false)
    apiPublicKey: 'Your API Public Key', // Enter your API Public Key here
    apiSecretKey: 'Your API Secret Key', // Enter your API Secret Key here
    unwantedVisitorTo: 'https://google.com', // URL or HTTP error code for unwanted visitors based on `unwantedVisitorAction`
    unwantedVisitorAction: 1 // Action to take for unwanted visitors: 1 = Redirect, 2 = Iframe, 3 = Load content
};

// Create an instance of VisitorTrafficFiltering with the provided configuration
const filter = new VisitorTrafficFiltering(config);

// Middleware function to handle visitor requests.
app.use(async (req, res, next) => {
    try {
        await filter.evaluateVisitor(req, res);
    } catch (error) {
        return next(error);
    }
    next(!res.headersSent ? undefined : null);
});

// Route handler for the root URL
app.get('/', (req, res) => {
    res.send('Hello World!');
});

// Start the Express server and listen on the specified port
app.listen(port, () => {
    console.log(`Server running at http://localhost:${port}`);
});

Method 2: Manually Providing IP, User-Agent, Events, and Domain

const { VisitorTrafficFiltering } = require('moonito');

/**
 * Configuration object for VisitorTrafficFiltering
 * This configuration is used to set up the AnalyticsHandler instance for handling visitor requests.
 * To use the API, you need to set up your public and secret API keys.
 *
 * Visit https://moonito.net/api for more details.
 */
const config = {
    isProtected: true, // Enable protection for the site (true) or disable it (false)
    apiPublicKey: 'Your API Public Key', // Enter your API Public Key here
    apiSecretKey: 'Your API Secret Key', // Enter your API Secret Key here
    unwantedVisitorTo: 'https://google.com', // URL or HTTP error code for unwanted visitors based on `unwantedVisitorAction`
    unwantedVisitorAction: 1 // Action to take for unwanted visitors: 1 = Redirect, 2 = Iframe, 3 = Load content
};

// Create an instance of VisitorTrafficFiltering with the provided configuration
const filter = new VisitorTrafficFiltering(config);

// Example visitor data
const userIP = '1.1.1.1'; // Replace with the visitor's IP
const userAgent = 'Mozilla/5.0 ...'; // Replace with the visitor's User-Agent
const event = 'page-view'; // Example event
const domain = 'example.com'; // Example domain

// Manually evaluate visitor
filter.evaluateVisitorManually(userIP, userAgent, event, domain)
    .then(result => {
        console.log('Visitor evaluation result:', result);

        if (result.need_to_block) {
            // You can handle blocked content here, e.g., displaying it on the page or redirecting
            console.log('Blocked content:', result.content);
            return;
        }

        console.log('Visitor is not blocked.');
    })
    .catch(error => {
        console.error('Unexpected error:', error);
    });

Replace Your API Public Key and Your API Secret Key with your actual Moonito API credentials in both methods.

Contributing

We welcome contributions! For significant changes, please open an issue to discuss the proposed modifications. Make sure to update tests as necessary.

License

This project is licensed under the MIT license.