AnakinIRCTC is a project for railway management system built using Node.js and PostgreSQL.
Before running this project, make sure you have the following installed:
-
Open PostgreSQL shell and run the following commands to set up the database:
CREATE DATABASE anakinirctc; CREATE TABLE users ( username VARCHAR PRIMARY KEY, password VARCHAR NOT NULL ); CREATE TABLE trains ( train_id VARCHAR PRIMARY KEY, source VARCHAR NOT NULL, destination VARCHAR NOT NULL, seats INTEGER NOT NULL CHECK (seats >= 0) ); CREATE TABLE bookings ( booking_id SERIAL PRIMARY KEY, username VARCHAR NOT NULL REFERENCES users(username), train_id VARCHAR NOT NULL REFERENCES trains(train_id) );
-
Create a .env file in the root directory of the project and add the required environment variables.
-
Install dependencies by running the following command in the terminal:
npm install
-
Finally, run the server using the following command:
node index.js
URL: /user/registration
Method: POST
Request Body:
{
"username": "akarsh1",
"password": "pass1"
}
URL: /user/login
Method: POST
Request Body:
{
"username": "akarsh1",
"password": "pass1"
}
Response: JWT token
URL: /train/add
Method: POST
Request Body:
{
"train_id": "train1",
"source": "source1",
"destination": "destination1",
"seats": 5
}
Header: Requires 'api-key' in header
URL: /train/updateseats/:train_id
Method: PUT
Request Body:
{
"seats": 2
}
Header: Requires 'api-key' in header
URL: /train/get
Method: GET
Request Body:
{
"source": "source1",
"destination": "destination"
}
URL: /booking/add/:train_id
Method: POST
Authorization: JWT token as bearer token
URL: /booking/get
Method: GET
Authorization: JWT token as bearer token