A powerful web scraping tool for tracking product prices with Telegram notifications.
This project has a companion mobile application built with React Native. You can find it at Price Scraper App.
- Node.js v18.0.0 or higher
- SQLite installed on your system
- Node.js and Yarn package manager
- Playwright for web scraping
-
Install Dependencies
yarn install
Note: While
npm installcan also be used, we recommend using Yarn for better dependency management and faster installation. -
Database Setup
- Copy the database from
/database/price_scraper.dbto the project root directory
- Copy the database from
-
Environment Configuration
- Copy the
envfile and rename it to.env - See Environment Variables Guide for detailed configuration
- Copy the
-
SQLite Installation
- Linux:
sudo apt install sqlite3 - macOS: Check if installed with
sqlite3 --version - Official SQLite Download Page
- Linux:
-
Playwright Installation
npx playwright install
-
Create a Telegram bot to receive notifications:
- Get your bot token from Telegram Bot API
- Set the token in
.envasTELEGRAM_BOT_TOKEN
-
Get your Chat ID:
- Send a message to your bot
- Visit:
https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/getUpdates - Find your
chat.idin the response - Set it in
.envasTELEGRAM_BOT_CHAT_ID
-
Test Telegram Configuration:
- Open: http://{localhost}:{8082}/api/test/telegram
- This will verify if your Telegram bot is properly configured
To run database migration scripts, use the following command. This is useful when you need to apply schema changes to your database.
To run a migration script on the main price_scraper.db database, execute the following command, replacing [migration_file.js] with the name of the migration file you want to run:
DB_PATH=price_scraper.db node scripts/migrations/[migration_file.js]For example, to run the script 001_add_referred_code_to_product_scraped.js, you would use:
DB_PATH=price_scraper.db node scripts/migrations/001_add_referred_code_to_product_scraped.jsThis command sets the DB_PATH environment variable to point to the price_scraper.db file in the root directory and then executes the migration script.
The application consists of two main components:
node server.js- Manages products, rules, and scraping configurations
- Access API documentation at
http://localhost:{PORT}/api-docs
node scraper.js- Core scraping functionality
- Runs at intervals specified in
.env - Sends notifications via Telegram when price changes are detected
Access the API documentation at:
http://localhost:{PORT}/api-docs
Replace {PORT} with your configured port number (default: 8082).
Before running any of the scripts, you need to make them executable. Run the following command in your terminal:
chmod +x setup-docker.sh update-docker.sh backup-db.sh restore-db.shThis command will:
- Make all Docker-related scripts executable
- Allow you to run them using
./script-name.sh - Ensure proper execution of the scripts
Note:
If you get a "Permission denied" error when trying to run a script,
make sure you've applied the permissions using the command above.
This guide explains how to build and run the Price Scraper application using Docker on different computer types.
The application needs environment variables to work properly. These variables are stored in a .env file. Make sure to create this file before running the container.
- The
.envfile is crucial for the application to work correctly - Never commit the
.envfile to git (it should be in .gitignore) - Keep a
.env.examplefile in the repository as a template - For detailed environment configuration, see Environment Variables Guide
To build and run the project in Docker, simply use the provided script:
./setup-docker.shThis script will:
- Ask you for the architecture (ARM64, AMD64, or both).
- Build the Docker image.
- Start the container with the correct port mapping.
- Copy the database file into the container.
After running the script, you can access the API at http://localhost:8082.
Note:
You no longer need to rundocker buildx build,docker run, or manually copy the database file.
The script handles everything for you.
The application uses Docker volumes to persist the database data. This is crucial for maintaining your data between container restarts and updates.
-
Setup Docker Environment (
setup-docker.sh):./setup-docker.sh
- Creates a Docker volume for the database
- Builds and starts the container
- Initializes the database if it's the first run
- Sets up the complete Docker environment
-
Update Application (
update-docker.sh):./update-docker.sh
- Automatically creates a backup before updating
- Pulls latest changes from git
- Rebuilds the container
- Preserves the database volume
- IMPORTANT: Always use this script for updates instead of manual commands
-
Backup Database (
backup-db.sh):./backup-db.sh
- Creates a timestamped backup of your database
- Stores backups in the
./backupsdirectory - Automatically keeps only the last 5 backups
- IMPORTANT: Run this before any major updates or container rebuilds
-
Restore Database (
restore-db.sh):./restore-db.sh ./backups/db-backup-YYYYMMDD-HHMMSS.tar.gz
- Restores a specific backup
- Automatically handles container restart
- Use this if you need to recover from a backup
-
Regular Backups
- Make regular backups of your database
- Store backups in a safe location
- Consider automating backups with cron jobs
-
Before Updates
- Always create a backup before updating the container
- Use
./backup-db.shto ensure data safety
-
Volume Management
- The database is stored in a Docker volume named
price-scraper-db - Never delete this volume unless you have a backup
- Use
docker volume lsto verify the volume exists
- The database is stored in a Docker volume named
-
Troubleshooting If you encounter database issues:
- Check if the volume exists:
docker volume ls | grep price-scraper-db - Verify container status:
docker ps | grep price-scraper - Check container logs:
docker logs price-scraper - Restore from backup if necessary
- Check if the volume exists:
# List all volumes
docker volume ls
# Inspect volume details
docker volume inspect price-scraper-db
# Remove volume (CAUTION: only if you have a backup)
docker volume rm price-scraper-db
# View container logs
docker logs price-scraperWARNING:
Never delete the Docker volume without having a backup.
Always run./backup-db.shbefore any major changes to the container.
After starting the container, you can test if it's working by visiting these URLs in your web browser:
-
API Documentation:
- Open: http://localhost:8082/api-docs/#/Products
- This shows all available API endpoints
-
Test Endpoint:
- Open: http://localhost:8082/api/test/
- You should see "Server is working!"
- The scraper runs automatically inside the container - you don't need to start it manually
- The application uses port 8082 - make sure this port is free on your computer
- The API documentation is available at http://localhost:8082/api-docs
- All data is stored in a SQLite database inside a Docker volume
- Always use the
--env-file .envflag when running the container to ensure all environment variables are loaded - Remember to rebuild the container after pulling new changes from the repository
- Make regular backups of your database volume
If you can't access the application:
- Check if the container is running:
docker ps - Make sure port 8082 is not used by another application
- Verify that your
.envfile exists and has the correct variables - Try stopping and removing the container:
Then start it again with the run command above.
docker stop $(docker ps -q) docker rm $(docker ps -aq)