An API for managing expenses. This project allows users to create, read, update, and delete expenses, as well as manage authentication through JWT.
- Features
- Tech Stack
- Setup
- Environment Variables
- Usage
- API Endpoints
- Error Handling
- Contributing
- License
- User authentication with JWT
- Create, view, update, and delete expenses
- Filter expenses by different time ranges (e.g., past week, past month)
- Secure endpoints with JWT authorization
- Node.js - Backend runtime environment
- Express - Web framework for building RESTful APIs
- Prisma ORM - Database ORM (Object Relational Mapping) for interacting with MongoDB
- TypeScript - Static typing for JavaScript
- JWT - JSON Web Tokens for secure authentication
- MongoDB - Database for storing user and expense data
- Node.js (version 14 or above)
- MongoDB (or use MongoDB Atlas for a cloud database)
- Git for version control
-
Clone the repository:
git clone https://github.com/your-username/expense-tracker-api.git cd expense-tracker-api
-
Install dependencies:
npm install
-
Set up environment variables (see Environment Variables).
-
Run database migrations (if using Prisma):
npx prisma migrate dev
yarn run dev
yarn run build
yarn run start
Create a .env
file in the root directory of the project with the following environment variables:
DATABASE_URL=mongodb://localhost:27017/your-database-name
JWT_SECRET=your_jwt_secret_key
PORT=3000
- Register a new user by sending a
POST
request to/api/auth/register
with a JSON body containingemail
andpassword
fields. - Log in with the registered user by sending a
POST
request to/api/auth/login
with the same JSON body. - Use the JWT token received in the response to authenticate requests to protected endpoints.
POST /api/auth/register
- Register a new userPOST /api/auth/login
- Log in with an existing user
GET /api/expenses
- Get all expensesPOST /api/expenses
- Create a new expensePUT /api/expenses/:id
- Update an expense by IDDELETE /api/expenses/:id
- Delete an expense by ID