Skip to content

A lightweight Node.js application that tracks webpage visitors and generates a dynamic SVG badge displaying the visitor count, powered by MongoDB.

License

Notifications You must be signed in to change notification settings

bitwisebro/ViewCounter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ViewCounter

This project is a simple Node.js application that tracks page views for different users and returns an SVG badge displaying the visitor count. It uses MongoDB to store the visitor count for each unique username.

Features

  • SVG Badge Generation: Displays visitor count in a badge format.
  • MongoDB Integration: Stores and updates visitor counts in a MongoDB database.
  • API-based Tracking: Tracks unique page views based on the username query parameter.

Prerequisites

  • Node.js
  • MongoDB (locally or hosted on MongoDB Atlas)

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/ViewCounter.git
  2. Navigate to the project directory:

    cd ViewCounter
  3. Install dependencies:

    npm install
  4. Create a .env file in the root directory with the following content:

    MONGODB_URI=your_mongodb_connection_string
    DB_NAME=your_database_name
  5. Start the server:

    npm start

The server will be running on http://localhost:3001.

Usage

To track visitor counts, make a GET request to the root endpoint with a username query parameter:

http://localhost:3001/?username=yourusername

This will return an SVG badge displaying the current page views for the specified user.

Example Response

(todo: add screenshot here)

The badge will display the following information:

  • Page Views: A fixed label indicating the type of statistic being displayed.
  • Visitor Count: The current visitor count for the given username.

API Endpoints

  • GET /: Retrieve and increment the visitor count for a given username and return an SVG badge.

Example Request

curl "http://localhost:3001/?username=exampleUser"

Customization

You can modify the appearance of the badge by updating the getBadge function in server.js. The function returns an SVG string, which can be customized to suit your design needs.

License

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


About

A lightweight Node.js application that tracks webpage visitors and generates a dynamic SVG badge displaying the visitor count, powered by MongoDB.

Topics

Resources

License

Stars

Watchers

Forks