Version Radar is a dynamic Node.js (TypeScript) application that monitors a software's webpage for version updates. It:
- Web-scrapes the specified URL to extract the software version.
- Stores the version information in a MongoDB database.
- Schedules the scraping task to run 3 times a day.
- Updates the database if a new version is detected.
- Sends email notifications when a new version is available.
- Provides an API to access the current version
- Features
- Prerequisites
- Installation
- Configuration
- Usage
- Troubleshooting
- Project Structure
- Contributing
- License
- Acknowledgements
- Contact
- Disclaimer
- Dynamic Web Scraping: Uses Cheerio to scrape dynamic elements from a webpage.
- Version Detection: Extracts and identifies software version numbers using regular expressions.
- Database Storage: Stores and updates version information in MongoDB.
- Email Notifications: Sends an email alert when a new version is detected.
- Scheduling: Runs the scraping task at specified times using
node-cron
. - Express Server with API Endpoints: Provides an API to access the current version.
- Configuration via Environment Variables: Easily adjust settings without changing the code.
- Node.js (v12 or higher)
- npm (Node Package Manager)
- MongoDB database (local or hosted, e.g., MongoDB Atlas)
- Email Account (for sending notifications, e.g., Gmail)
-
Clone the Repository
git clone https://github.com/Harshalkatakiya/version-radar.git cd version-radar
-
Install Dependencies
npm install
Create a .env
file in the root directory and configure the following variables:
# Application Configuration
PORT=3000
SOFTWARE_URL=https://example.com/software-page
SOFTWARE_NAME=SoftwareName
SOFTWARE_SELECTOR=.your-css-selector
VERSION_REGEX=\d+(\.\d+)+
VERSION_FORMAT=X.Y
# Database Configuration
MONGODB_URI=your_mongodb_connection_string
# Email Configuration
EMAIL_USER=your_email@example.com
EMAIL_PASS=your_email_password
RECIPIENT_EMAIL=recipient_email@example.com
PORT
: The port on which the server will run (default is3000
).SOFTWARE_URL
: The URL of the software page to scrape.SOFTWARE_NAME
: Name of the software you're tracking.SOFTWARE_SELECTOR
: CSS selector to target elements containing version numbers.VERSION_REGEX
: Regular expression to match version numbers.VERSION_FORMAT
: Expected version format (X.Y
,X.Y.Z
, etc.).MONGODB_URI
: Connection string for your MongoDB database.EMAIL_USER
andEMAIL_PASS
: Credentials for the email account used to send notifications.RECIPIENT_EMAIL
: Email address to receive notifications.
For Gmail accounts:
- Enable Less Secure Apps or use an App Password.
- Ensure that 2-Step Verification is set up if using App Passwords.
npm start
The will compile the TypeScript code and start the server. It will start on the specified PORT
(default 3000
).
The application uses node-cron
to schedule the scraping task. By default, it runs at 00:00
, 08:00
, and 16:00
every day. You can adjust the schedule in src/index.ts
:
cron.schedule("0 0,8,16 * * *", () => {
console.log("β³ Running scheduled task...");
scrapeVersion();
});
-
URL:
/
-
Method:
GET
-
Description: Returns a welcome message.
-
Response:
Welcome to Version Radar π‘
-
URL:
/current-version
-
Method:
GET
-
Description: Retrieves the current version information from the database.
-
Response:
-
Success (200):
{ "data": { "_id": "60f7f0b4c2a1a45b6c8e4d1a", "softwareName": "SoftwareName", "version": "2.10", "updatedAt": "2024-11-22T12:34:56.789Z", "createdAt": "2024-11-22T12:34:56.789Z", "__v": 0 } }
-
Not Found (404):
{ "message": "Version information not found." }
-
Error (500):
{ "message": "Error fetching version information." }
-
- Cause: The version number is not being correctly extracted.
- Solution:
- Check the
SOFTWARE_SELECTOR
to ensure it's targeting the correct elements. - Adjust the
VERSION_REGEX
to match the version format on the webpage. - Use console logs to debug the elements and text being processed.
- Check the
- Cause: Incorrect email configuration or authentication issues.
- Solution:
- Verify
EMAIL_USER
,EMAIL_PASS
, andRECIPIENT_EMAIL
in your.env
file. - Ensure that your email account allows SMTP access.
- Check for any security notifications from your email provider.
- Verify
- Cause: Incorrect MongoDB URI or network issues.
- Solution:
- Verify the
MONGODB_URI
in your.env
file. - Ensure that your MongoDB instance is running and accessible.
- Check for any IP whitelist or network restrictions in MongoDB Atlas.
- Verify the
version-radar/
βββ src/
β βββ models/
β β βββ version.ts
β βββ index.ts
β βββ scraper.ts
βββ .env
βββ .gitignore
βββ LICENSE
βββ package.json
βββ README.md
βββ tsconfig.json
Contributions are welcome! Please follow these steps:
-
Fork the Repository
Click on the 'Fork' button at the top right corner of the repository page.
-
Clone Your Fork
git clone https://github.com/Harshalkatakiya/version-radar.git
-
Create a New Branch
git checkout -b feature/your-feature-name
-
Make Your Changes
-
Commit Your Changes
git commit -m 'Add new feature'
-
Push to the Branch
git push origin feature/your-feature-name
-
Create a Pull Request
Go to the original repository and click on 'New Pull Request'.
This project is licensed under the MIT License.
- Node.js: Runtime environment for executing JavaScript code server-side.
- TypeScript: Typed superset of JavaScript that compiles to plain JavaScript.
- Express: Fast, unopinionated, minimalist web framework for Node.js.
- Cheerio: Fast, flexible, and lean implementation of core jQuery designed specifically for the server.
- Mongoose: Elegant MongoDB object modeling for Node.js.
- Node-Cron: Task scheduler for Node.js.
- Nodemailer: Module for Node.js applications to allow easy email sending.
- dotenv: Module that loads environment variables from a
.env
file.
For any questions or suggestions, please open an issue or contact Harshal Katakiya.
This project is intended for educational and personal use. Please ensure that you have the right to scrape the target website and comply with their terms of service.
Thank you for using Version Radar! If you find this project useful, please give it a star on GitHub. β
Happy coding! π