This repository contains a Node.js REST API for managing student data. It includes functionality to retrieve a list of students, get a student by their ID, add a new student, update an existing student's name, and remove a student. This API is built using Express.js and interacts with a PostgreSQL database.
Before you begin, ensure you have met the following requirements:
-
Node.js: Make sure you have Node.js installed on your machine. You can download it from nodejs.org.
-
PostgreSQL: You need a PostgreSQL database up and running. Make sure you have the necessary connection details.
-
Clone this repository to your local machine:
git clone <repository-url>
-
Navigate to the project directory:
cd <project-directory>
-
Install the project dependencies using npm:
npm install
The API uses environment variables to configure database connections. Create a .env
file in the root directory of the project and define the following variables:
DB_HOST=your-database-host
DB_PORT=your-database-port
DB_NAME=your-database-name
DB_USER=your-database-user
DB_PASSWORD=your-database-password
Make sure to replace your-database-host
, your-database-port
, your-database-name
, your-database-user
, and your-database-password
with your actual database connection details.
The API has a PostgreSQL database with a table named students
. db.js file
To start the API server, run the following command:
npm start
The server will start on port 3000 by default. You can access it by opening a web browser and navigating to http://localhost:3000
.
The API provides the following endpoints:
GET /api/v1/students
: Get a list of all students.GET /api/v1/students/:id
: Get a student by their ID.POST /api/v1/students
: Add a new student.PUT /api/v1/students/:id
: Update a student's name by their ID.DELETE /api/v1/students/:id
: Remove a student by their ID.
GET /api/v1/students
GET /api/v1/students/1
POST /api/v1/students
Request Body:
{
"name": "John Doe",
"email": "john@example.com",
"age": 20,
"dob": "2003-01-15"
}
PUT /api/v1/students/1
Request Body:
{
"name": "Jane Doe"
}
DELETE /api/v1/students/1
Contributions are welcome! If you'd like to contribute to this project, please follow these guidelines:
-
Fork the repository and create a new branch for your feature or bug fix.
-
Make your changes and test thoroughly.
-
Ensure your code follows the existing coding style.
-
Create a pull request with a clear description of your changes.
This project is licensed under the MIT License - see the LICENSE file for details.