The task involved creating a Node.js-based API using NestJS that interacts with a PostgreSQL database. The API supports CRUD (create, read, update, and delete) operations, implements user authentication and authorization using JSON Web Tokens (JWTs), and includes error handling and validation.
-
NestJS: This project uses NestJS, a powerful and extensible Node.js framework, to build the API.
-
PostgreSQL: The PostgreSQL database is used for storing and managing data.
-
TypeORM: TypeORM is utilized to define the data schema and interact with the PostgreSQL database.
-
JWT Authentication: JSON Web Tokens (JWTs) are implemented for user authentication and authorization.
-
Validation: Class-validator pipes are used to validate the data passed in the request body.
-
Swagger Documentation: Swagger documentation is included for clear API documentation and testing.
-
Docker for PostgreSQL: Instructions for setting up a PostgreSQL database using Docker are provided.
-
Git and GitHub: Git is used for version control, and the code is hosted on GitHub.
Before running the project, ensure you have the following dependencies installed:
Follow these steps to run the project:
-
Clone the repository to your local machine:
git clone [email protected]:SubstantialCattle5/SocialMediaBackend.git
-
Install the project dependencies:
cd SocialMediaBackend yarn
-
Set up the PostgreSQL database using Docker:
docker compose -up dev-db d
-
Create a
.env
file in the project root and configure the database connection:DB_HOST=localhost DB_PORT=5432 DB_USERNAME=postgres DB_PASSWORD=postgres DB_DATABASE=postgres
-
Start the NestJS application:
yarn run start:dev
-
The API should now be running locally. You can access the Swagger documentation at http://localhost:3000/docs to explore and test the API endpoints.
POST /auth/register
: Register a new user.POST /auth/login
: Log in and receive a JWT token.
GET /tweet
: Get a list of all tweets.GET /tweet/:id
: Get a single tweet by ID.POST /tweet
: Create a new tweet (requires authentication).PUT /tweet/:id
: Update an existing tweet (requires authentication).DELETE /tweet/:id
: Delete a tweet (requires authentication).