A Node.js/Express backend API for managing financial transactions with PostgreSQL database.
- ✅ Add new transactions
- ✅ Retrieve transactions by user
- ✅ PostgreSQL database with Prisma ORM
- ✅ Railway deployment ready
- ✅ Input validation and error handling
- ✅ CORS enabled for frontend integration
- Runtime: Node.js
- Framework: Express.js
- Database: PostgreSQL
- ORM: Prisma
- Deployment: Railway
GET /
Returns server status.
POST /transactions
Request Body:
{
"amount": 100.50,
"type": "Grocery shopping",
"category": "Food",
"subcategory": "Groceries", // optional
"comments": "Weekly grocery shopping", // optional
"date": "2024-01-15T10:30:00Z", // optional, defaults to current date
"userId": 1
}Response:
{
"message": "Transaction added successfully",
"transaction": {
"id": 1,
"amount": 100.50,
"type": "Grocery shopping",
"category": "Food",
"subcategory": "Groceries",
"comments": "Weekly grocery shopping",
"date": "2024-01-15T10:30:00Z",
"userId": 1,
"createdAt": "2024-01-15T10:30:00Z",
"updatedAt": "2024-01-15T10:30:00Z"
}
}GET /transactions?userId=1
Response:
{
"transactions": [
{
"id": 1,
"amount": 100.50,
"type": "Grocery shopping",
"category": "Food",
"subcategory": "Groceries",
"comments": "Weekly grocery shopping",
"date": "2024-01-15T10:30:00Z",
"userId": 1,
"createdAt": "2024-01-15T10:30:00Z",
"updatedAt": "2024-01-15T10:30:00Z"
}
],
"count": 1
}- Node.js (v18 or higher)
- npm or yarn
- PostgreSQL database
- Clone and install dependencies:
npm install- Set up environment variables:
Create a
.envfile in the root directory:
DATABASE_URL="postgresql://username:password@localhost:5432/finquest"
PORT=3000
NODE_ENV=development- Set up the database:
# Generate Prisma client
npm run db:generate
# Push schema to database (for development)
npm run db:push
# Or run migrations (for production)
npm run db:migrate- Start the development server:
npm run devThe server will start on http://localhost:3000
- Railway account
- GitHub repository with this code
-
Connect to Railway:
- Go to Railway
- Connect your GitHub repository
- Create a new project
-
Add PostgreSQL Database:
- In your Railway project, click "New"
- Select "Database" → "PostgreSQL"
- Railway will automatically set the
DATABASE_URLenvironment variable
-
Deploy the Application:
- Railway will automatically detect the Node.js app
- The
startscript inpackage.jsonwill be used - Railway will install dependencies and start the server
-
Set up the Database:
- After deployment, run database migrations:
# Connect to Railway shell or use Railway CLI npx prisma db push
Railway will automatically set:
DATABASE_URL(from PostgreSQL service)PORT(Railway sets this automatically)
- In Railway dashboard, go to your service
- Click "Settings" → "Domains"
- Add your custom domain
Health Check:
curl http://localhost:3000/Add Transaction:
curl -X POST http://localhost:3000/transactions \
-H "Content-Type: application/json" \
-d '{
"amount": 100.50,
"type": "Grocery shopping",
"category": "Food",
"subcategory": "Groceries",
"comments": "Weekly grocery shopping",
"userId": 1
}'Get Transactions:
curl "http://localhost:3000/transactions?userId=1"Import these requests:
-
Health Check:
- Method: GET
- URL:
http://localhost:3000/
-
Add Transaction:
- Method: POST
- URL:
http://localhost:3000/transactions - Headers:
Content-Type: application/json - Body (raw JSON):
{ "amount": 100.50, "type": "Grocery shopping", "category": "Food", "subcategory": "Groceries", "comments": "Weekly grocery shopping", "userId": 1 } -
Get Transactions:
- Method: GET
- URL:
http://localhost:3000/transactions?userId=1
The Transaction model includes:
id: Auto-incrementing primary keyamount: Decimal field for transaction amounttype: Text description of the transactioncategory: Transaction category (e.g., Food, Transport, etc.)subcategory: Optional subcategory for more detailed classificationcomments: Optional additional notes or commentsdate: Transaction date (defaults to current date)userId: User identifier (for future user system)createdAt: Timestamp when record was createdupdatedAt: Timestamp when record was last updated
The API includes comprehensive error handling:
- 400 Bad Request: Missing required fields or invalid data
- 500 Internal Server Error: Database or server errors
All errors return JSON responses with error details.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
ISC License