A Node.js backend application for tracking stock prices and managing watchlists.
- Real-time stock price updates using WebSocket
- RESTful API for stock data and watchlist management
- Rate limiting for API protection
- Input validation
- Structured logging
- Docker support
- Node.js (v18 or higher)
- MongoDB
- Docker (optional)
Create a .env file in the root directory with the following variables:
PORT=5000
MONGODB_URI=mongodb://localhost:27017/stock-tracker
YAHOO_FINANCE_API_KEY=your_api_key_here
YAHOO_FINANCE_API_HOST=your_api_host_here
LOG_LEVEL=info
- Clone the repository
- Install dependencies:
npm install
- Start the development server:
npm run dev
GET /api/v1/stocks/:symbol- Get stock summaryGET /api/v1/stocks/:symbol/history- Get historical dataGET /api/v1/stocks/search- Search stocksGET /api/v1/stocks/quotes- Get multiple stock quotes
POST /api/v1/watchlist/users/create- Create new userGET /api/v1/watchlist/:userId- Get user's watchlistPOST /api/v1/watchlist/:userId/add- Add stock to watchlistDELETE /api/v1/watchlist/:userId/:symbol- Remove stock from watchlistGET /api/v1/watchlist/:userId/with-data- Get watchlist with current stock data
Build and run the application using Docker:
docker build -t stock-tracker-backend .
docker run -p 5000:5000 stock-tracker-backend- Run tests:
npm test - Start development server:
npm run dev
- Rate limiting is implemented to prevent abuse
- Input validation for all endpoints
- Environment variables for sensitive data
- CORS enabled for API access
Logs are stored in the logs directory:
error.log- Error logscombined.log- All logs
ISC