Node.js and Express API for managing a personal budget using Envelope Budgeting principles.
MIT License
This is a Node.js and Express API for managing a personal budget using Envelope Budgeting principles. The API allows users to create, read, update, and delete budget envelopes, transfer funds between envelopes, and supports user authentication with JWT.
Register a New User
POST /auth/register
Request body:
{
"username": "your_username",
"password": "your_password"
}
Response:
{
"message": "User registered successfully",
"userId": 1
}
Login
POST /auth/login
Request body:
{
"username": "your_username",
"password": "your_password"
}
Response:
{
"message": "Login successful",
"token": "your_jwt_token"
}
All envelope-related routes are protected and require a valid JWT token. Include the token in the Authorization
header as Bearer <your_jwt_token>
.
Create Envelope
POST /envelopes
Request Body:
{
"title": "Groceries",
"budget": 500
}
Response:
{
"message": "Envelope created successfully",
"envelope": {
"id": 1,
"title": "Groceries",
"budget": 500
}
}
Get All Envelopes
GET /envelopes
Response:
{
"envelopes": [
{
"id": 1,
"title": "Groceries",
"budget": 500
},
{
"id": 2,
"title": "Dining Out",
"budget": 200
}
]
}
Get Envelope by ID
GET /envelopes/:id
Response:
{
"id": 1,
"title": "Groceries",
"budget": 500
}
Update Envelope
PUT /envelopes/:id
Request body:
{
"title": "Groceries",
"budget": 600
}
Response:
{
"message": "Envelope updated successfully",
"envelope": {
"id": 1,
"title": "Groceries",
"budget": 600
}
}
Delete Envelope
DELETE /envelopes/:id
Response:
{
"message": "Envelope deleted successfully"
}
Transfer Funds Between Envelopes
POST /envelopes/transfer/:from/:to
Request body:
{
"amount": 100
}
Response:
{
"message": "Transfer completed successfully",
"fromEnvelope": {
"id": 1,
"title": "Groceries",
"budget": 400
},
"toEnvelope": {
"id": 2,
"title": "Dining Out",
"budget": 300
}
}
git clone https://github.com/makrischaralampos/personal-budget.git
cd personal-budget
npm install
Create a .env
file in the root of your project and add the following:
JWT_SECRET=your_jwt_secret_key
JWT_EXPIRES_IN=1h
node server.js
The server will run on http://localhost:3000
.
Use Postman or similar tools to test the API endpoints. Make sure to include the JWT token in the Authorization
header for protected routes.
This project is licensed undet the MIT License - see the LICENSE file for details.