- Overview
- Key Features
- Technologies Used
- Run the Server Locally
- Authentication
- Blog Management
- Admin Actions
- Search, Sort & Filter Blogs
- Error Handling
Wink Blog is a robust backend built for managing blogs with user authentication, role-based access control, and API functionalities. It supports Admin and User roles with tailored permissions and features.
- User Authentication & Authorization: Secure login with role-based access control (Admin, User).
- Role Management: Admins manage all blogs and users, while users manage their own content.
- JWT-Based Security: Secure session management using access and refresh tokens.
- Middleware Protection: Role-based access enforced through middleware.
- Blog Management: Full CRUD operations with ownership validation.
- Search, Sort & Filter: Powerful querying using a reusable
QueryBuilder
. - Password Encryption: Secure password hashing using bcrypt.
- Data Validation: Input validation using Zod schemas.
- Scalable Architecture: Modular backend design for easy maintainability.
- TypeScript – Typed JavaScript for scalability.
- Node.js – JavaScript runtime.
- Express.js – Web framework.
- Mongoose – MongoDB object modeling.
- bcrypt – Password hashing.
- jsonwebtoken – JWT implementation.
- cookie-parser – Cookie parsing.
- zod – TypeScript-first schema validation.
- cors – Enables CORS in Express.
- dotenv – Loads environment variables from
.env
.
- Node.js (v20+)
- npm package manager
-
Clone the repository:
git clone https://github.com/nazim1971/wing-blog.git cd wing-blog
-
Install dependencies:
npm install
-
Set up environment variables in
.env
file:PORT=your_port DATABASE_URI=your_mongo_uri BCRYPT_SALT_ROUNDS=your_salt_rounds DEFAULT_PASS=your_default_password NODE_ENV=development JWT_ACCESS_SECRET=your_access_secret JWT_REFRESH_SECRET=your_refresh_secret
-
Start the development server:
npm run dev
The server will be running at http://localhost:your_port.
- Method:
POST
- Endpoint:
/api/auth/register
- Request Body:
{ "name": "John Doe", "email": "john@example.com", "password": "123456" }
- Response:
{ "success": true, "message": "User registered successfully!", "statusCode": 201, "data": { "_id": "string", "name": "string", "email": "string" } }
- Method:
POST
- Endpoint:
/api/auth/login
- Request Body:
{ "email": "john@example.com", "password": "123456" }
- Response:
{ "success": true, "message": "Login successful!", "statusCode": 200, "data": { "token": "string" } }
- Method:
POST
- Endpoint:
/api/blogs
- Request Header:
Authorization: Bearer <token>
- Request Body:
{ "title": "My First Blog", "content": "This is my blog content." }
- Response:
{ "success": true, "message": "Blog created successfully!", "statusCode": 201, "data": { "_id": "string", "title": "My First Blog", "content": "This is my blog content.", "author": { "_id": "author id", "name": "author name", "email": "author email" } } }
- Method:
PATCH
- Endpoint:
/api/admin/users/:userId/block
- Request Header:
Authorization: Bearer <admin_token>
- Response:
{ "success": true, "message": "User blocked successfully!", "statusCode": 200 }
All error responses follow a consistent structure:
{
"success": false,
"message": "Error message",
"statusCode": 400,
"error": {
"details": [
{
"name": "Error name",
"path": "where error occurred",
"message": "Error message"
}
]
},
"stack": "Error stack trace if available"
}
- Email: wink@gmail.com
- Password: Wink123