# Node.js Backend for BSE Insider Trading Analyzer This directory contains a Node.js backend for fetching real BSE insider trading data using ScraperAPI. ## Key Features - Scrapes real data from BSE insider trading pages - Express.js API server for frontend integration - Scheduled data collection every 2 minutes - Automatic price updates for trades ## Setup Instructions ### Prerequisites - Node.js 14+ installed - NPM or Yarn package manager - ScraperAPI account (key already configured: `167259cf89a5c56e0e7ca670d6534743`) ### Installation 1. Install dependencies: ```bash cd nodejs npm install ``` 2. Start the server: ```bash npm start ``` For development with auto-restart: ```bash npm run dev ``` 3. The server will run on port 3000 by default (http://localhost:3000) ## API Endpoints - `GET /api/trades` - Get all insider trades - `GET /api/trades/:id` - Get a specific trade by ID - `POST /api/fetch` - Manually trigger data fetching - `POST /api/fetch-url` - Fetch data from a specific URL - `GET /health` - Server health check ## Integration with Frontend Update the frontend application to fetch data from this Node.js backend instead of using the PHP backend or simulated data: 1. Edit `scraper.js` to point to the Node.js backend API 2. The frontend can fetch trades using: `http://localhost:3000/api/trades` ## Important Notes - This backend must be running on a server to fetch real data - CORS is enabled for all origins, allowing requests from the frontend - Data is stored in `insider_trades.json` file - For production deployment, consider using PM2 or similar process manager ## Troubleshooting - If you encounter connection issues with ScraperAPI, check your API key and network settings - For CORS issues, ensure the frontend is making requests to the correct backend URL - If the server fails to start, check for port conflicts (default port: 3000)