A full-featured Content Management System built with Node.js, Express, and MySQL. This project demonstrates RESTful API development with authentication, authorization, and CRUD operations.
- 🔐 Authentication & Authorization
- JWT-based authentication
- Protected routes with middleware
- User registration and login
- 📄 Posts Management
- Create, read, update, and delete posts
- Public posts feed
- User-specific posts
- 🗂️ Categories System
- Organize posts into categories
- Full CRUD operations
- 👤 User Profiles
- View and update user profiles
- Secure password handling
- Backend: Node.js, Express.js
- Database: MySQL
- Authentication: JWT, bcryptjs
- Security: CORS, environment variables
- Architecture: MVC pattern
POST /api/auth/register- User registrationPOST /api/auth/login- User login
GET /api/posts- Get all posts (Public)GET /api/posts/my-posts- Get user's posts (Protected)GET /api/posts/:id- Get single postPOST /api/posts- Create new post (Protected)PUT /api/posts/:id- Update post (Protected)DELETE /api/posts/:id- Delete post (Protected)
GET /api/categories- Get all categoriesPOST /api/categories- Create categoryPUT /api/categories/:id- Update categoryDELETE /api/categories/:id- Delete category
GET /api/users/profile- Get user profile (Protected)PUT /api/users/profile- Update profile (Protected)
- Clone the repository
git clone https://github.com/Pmahdian/Nodejs-cms.git
cd nodejs-cms- Install dependencies
npm install- Set up environment variables
cp .env.example .env
# Edit .env with your database credentials- Database setup
CREATE DATABASE cms_database;- Run the application
npm startNodejs-cms/
│
├── 📁 src/
│ ├── 📁 config/
│ │ └── database.js # MySQL database configuration
│ │
│ ├── 📁 controllers/
│ │ ├── authController.js # Authentication logic (register/login)
│ │ ├── postController.js # Posts CRUD operations
│ │ ├── categoryController.js # Categories management
│ │ └── userController.js # User profile management
│ │
│ ├── 📁 middleware/
│ │ └── authMiddleware.js # JWT authentication middleware
│ │
│ ├── 📁 routes/
│ │ ├── auth.js # /api/auth/* routes
│ │ ├── posts.js # /api/posts/* routes
│ │ ├── categories.js # /api/categories/* routes
│ │ └── users.js # /api/users/* routes
│ │
│ └── server.js # Main server file
│
├── 📄 .env # Environment variables (sensitive)
├── 📄 .env.example # Environment variables template
├── 📄 .gitignore # Git ignored files
├── 📄 package.json # Project dependencies
├── 📄 README.md # Project documentation
└── 📄 LICENSE # Project license
📊 cms_database/
├── 👥 users table
│ ├── id (PRIMARY KEY)
│ ├── username
│ ├── email
│ ├── password (hashed)
│ └── created_at
│
├── 📝 posts table
│ ├── id (PRIMARY KEY)
│ ├── title
│ ├── content
│ ├── user_id (FOREIGN KEY → users.id)
│ ├── category_id (FOREIGN KEY → categories.id)
│ ├── created_at
│ └── updated_at
│
└── 🗂️ categories table
├── id (PRIMARY KEY)
├── name
├── description
└── created_at
{
"dependencies": {
"express": "^4.18.2",
"mysql2": "^3.6.5",
"bcryptjs": "^2.4.3",
"jsonwebtoken": "^9.0.2",
"dotenv": "^16.3.1",
"cors": "^2.8.5"
}
}Create a .env file with the following variables:
DB_HOST=localhost
DB_USER=your_username
DB_PASS=your_password
DB_NAME=cms_database
JWT_SECRET=your_jwt_secret
APP_PORT=3000Feel free to fork this project and submit pull requests for any improvements.
- Parnian Mahdian
- GitHub Profile
This project is open source and available under the MIT License.
⭐ Don't forget to star this repository if you find it useful!
