A simple stock exchange project that demonstrates how to manage buy/sell orders using Node.js, Express, MongoDB, and React.
- Features
- Tech Stack
- Prerequisites
- Installation
- Project Structure
- Running the Project
- Usage
- Troubleshooting
- Contributing
- License
- Order Management: Create and view stock orders (buy/sell).
- RESTful API: Node.js/Express handles backend routes.
- MongoDB Integration: Stores persistent orders.
- React Frontend: Displays orders in a table with Buy/Sell buttons.
- Backend: Node.js, Express, Mongoose (MongoDB driver)
- Database: MongoDB
- Frontend: React (Create React App)
- Node.js (v14+ recommended)
- npm (comes with Node) or yarn
- MongoDB (installed locally or running in a container)
-
Clone the Repository
git clone https://github.com/Konikz/Stock-Exchange.git cd Stock-Exchange
-
Install Root Dependencies
npm install
-
Install Frontend Dependencies
cd client npm install cd ..
-
Install Backend Dependencies
cd server npm install cd ..
Stock-Exchange
├── client
│ ├── src
│ │ ├── components
│ │ │ └── StockOrders.js
│ │ └── App.js
│ ├── package.json
│ └── ...
├── server
│ ├── index.js
│ ├── package.json
│ └── ...
├── package.json
└── README.md
- client/: React frontend.
- server/: Node.js + Express backend.
- package.json (root): Holds scripts for running both frontend & backend together using concurrently.
- If using a local MongoDB:
mongod --dbpath /data/db --bind_ip 0.0.0.0 --logpath /tmp/mongodb.log --logappend
- Or ensure your MongoDB service is running (e.g.,
service mongod start
).
From the project root, run:
npm run dev
This will:
- Start MongoDB (if configured in
dev
script). - Launch the Node.js server on port
3000
. - Launch the React app on port
3001
.
-
Open the Frontend
Visit http://localhost:3001 in your browser. -
Check the Backend
- API Endpoint: http://localhost:3000/api/orders
-
Placing Orders
- Currently, orders are fetched automatically from MongoDB.
- Use the Buy and Sell buttons (if implemented) to place or manage orders.
- Or send requests to the backend with Postman/cURL:
curl -X POST http://localhost:3000/api/orders \ -H "Content-Type: application/json" \ -d '{"stock":"AAPL","price":150,"quantity":10}'
-
MongoDB Connection Error
- Ensure MongoDB is running locally.
- Check your
mongoose.connect(...)
URI inserver/index.js
.
-
Port Already in Use
- If you see
EADDRINUSE: address already in use :::3000
, kill the existing process or change ports.
- If you see
-
CORS Errors
- Make sure you have
app.use(cors())
inserver/index.js
.
- Make sure you have
-
React Not Showing Data
- Check console logs in the browser dev tools.
- Confirm your API endpoint returns data at
http://localhost:3000/api/orders
.
- Fork the repo
- Create a new branch:
git checkout -b feature/my-feature
- Make changes and commit:
git commit -m 'Add my feature'
- Push to the branch:
git push origin feature/my-feature
- Create a Pull Request
This project is open-source. Feel free to modify or distribute it. If you add enhancements, consider contributing back!
Feel free to customize this README to match your exact project details. Happy coding!