This is a basic transaction management application built using Node.js, Express.js, and PostgreSQL. The application allows users to create accounts, perform credit and debit transactions, and view their transaction history.
- Create a user with an initial balance.
- Perform credit or debit transactions.
- View transaction history for a specific user.
- Node.js installed on your machine.
- PostgreSQL installed and configured on your machine or an external PostgreSQL service.
curlor Postman for testing API endpoints.
git clone https://github.com/yourusername/transaction-app.git
cd transaction-appnpm installIn the root of your project directory, create a .env file to store your environment variables. Here is the format you should follow:
DB_URL=<your_database_url>
PORT=3000Replace <your_database_url> with the full external database URL provided by your PostgreSQL service.
Make sure PostgreSQL is installed on your system or accessible as a cloud service. You should create the necessary tables for users and transactions in your database. Here is an example of what the SQL schema might look like:
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
balance NUMERIC(10, 2) NOT NULL
);
CREATE TABLE transactions (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
amount NUMERIC(10, 2) NOT NULL,
type VARCHAR(10) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);npm startThe server should now be running on http://localhost:3000.