A progressive Node.js framework for building efficient and scalable server-side applications.
A robust authentication system built with NestJS, MongoDB, and JWT, featuring user management and post creation capabilities. This project was developed using Windsurf, the world's first agentic IDE.
-
User Authentication
- JWT-based authentication
- Secure password hashing with bcrypt
- Login and registration endpoints
- Protected routes
-
User Management
- Create, read, update, and delete users
- Email validation
- Password validation
-
Post Management
- Create, read, update, and delete posts
- Posts associated with users
- Protected post endpoints
- Node.js (v14 or later)
- MongoDB database
- npm or yarn package manager
Create a .env
file in the root directory with the following variables:
DATABASE_URL="mongodb+srv://your-username:your-password@your-cluster-url/your-database?retryWrites=true&w=majority"
JWT_SECRET="your-jwt-secret"
PORT=3333
# Install dependencies
$ npm install
# Push database schema
$ npx prisma db push
# Generate Prisma client
$ npx prisma generate
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
Once the application is running, visit http://localhost:3333/api
to access the Swagger documentation.
- POST
/auth/register
- Register a new user - POST
/auth/login
- Login and receive JWT token
Users:
- GET
/users
- Get all users - GET
/users/:id
- Get user by ID - PATCH
/users/:id
- Update user - DELETE
/users/:id
- Delete user
Posts:
- GET
/posts
- Get all posts - GET
/posts/:id
- Get post by ID - POST
/posts
- Create new post - PATCH
/posts/:id
- Update post - DELETE
/posts/:id
- Delete post
- Password hashing using bcrypt
- JWT token authentication
- Protected routes with Guards
- Input validation using class-validator
- Swagger API documentation with bearer auth
src/
├── auth/ # Authentication module
├── users/ # Users module
├── posts/ # Posts module
├── prisma/ # Prisma schema and migrations
└── main.ts # Application entry point
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
This project is MIT licensed.