This is a simple blog API built with NestJS, Prisma, and PostgreSQL. It provides a set of RESTful endpoints to manage users and posts in a blog application.
- User registration and authentication
- CRUD operations for posts
- Protected routes with JWT-based authentication
- Pagination and filtering support for fetching posts
- Node.js 12.x or higher
- npm or yarn
- PostgreSQL 10.x or higher
- Clone the repository:
git clone https://github.com/yourusername/nestjs-blog-api.git cd nestjs-blog-api
- Install the dependencies:
or
yarn
- Set up your PostgreSQL database and create a
.env
file in the project root. Add the following content to the file, replacing the placeholders with your actual database credentials:
DATABASE_URL=postgresql://user:password@localhost:5432/your_database_name JWT_SECRET=your_jwt_secret
- Apply the Prisma migration to create the database schema:
npx prisma migrate dev
- Start the development server:
npm run start:dev
or
yarn start:dev
The application will be available at http://localhost:3000
.
- Build and run the application in production mode:
npm run build npm run start:prod
or
yarn build yarn start:prod
- POST
/users
: Register a new user - GET
/users/:id
: Get a user by ID - GET
/users/profile
: Get the profile of the authenticated user - PUT
/users/profile
: Update the profile of the authenticated user
- POST
/posts
: Create a new post - GET
/posts
: Get all posts - GET
/posts/:id
: Get a post by ID - PUT
/posts/:id
: Update a post - DELETE
/posts/:id
: Delete a post
This project is licensed under the MIT License.