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.
- 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
usernamequery parameter.
- Node.js
- MongoDB (locally or hosted on MongoDB Atlas)
-
Clone the repository:
git clone https://github.com/yourusername/ViewCounter.git
-
Navigate to the project directory:
cd ViewCounter -
Install dependencies:
npm install
-
Create a
.envfile in the root directory with the following content:MONGODB_URI=your_mongodb_connection_string DB_NAME=your_database_name
-
Start the server:
npm start
The server will be running on http://localhost:3001.
To track visitor counts, make a GET request to the root endpoint with a username query parameter:
http://localhost:3001/?username=yourusernameThis will return an SVG badge displaying the current page views for the specified user.
(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.
- GET /: Retrieve and increment the visitor count for a given
usernameand return an SVG badge.
curl "http://localhost:3001/?username=exampleUser"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.
This project is licensed under the MIT License. See the LICENSE file for more details.