A simple, full-featured blog application built with Node.js, Express, MongoDB, and EJS. This project demonstrates core web development concepts including RESTful APIs, authentication, CRUD operations, and template rendering.
- User Authentication: Secure login system for administrators using JWT and cookies.
- Blog Posts: Create, read, update, and delete (CRUD) blog articles.
- Admin Dashboard: Manage posts through a protected admin interface.
- Pagination & Search: Paginated post listing and keyword search functionality.
- Responsive Design: Clean, responsive UI using EJS templates and CSS.
- MongoDB Integration: Uses Mongoose ODM for easy MongoDB interaction.
- Session Management: Sessions stored securely in MongoDB.
- Real-Time Ready: Project architecture ready for real-time features (Socket.io).
- Node.js
- Express.js
- MongoDB (with Mongoose)
- EJS (Embedded JavaScript templates)
- JWT for authentication
- bcrypt for password hashing
- express-session and connect-mongo for session management
- dotenv for environment variable management
- method-override for supporting PUT/DELETE in forms
-
Clone the repository:
git clone https://github.com/sanjaysaini383/NodeJS-Blog.git cd NodeJS-Blog -
Install dependencies:
npm install
-
Set up environment variables:
- Create a
.envfile in the root directory. - Add the following variables:
MONGODB_URI=your_mongodb_connection_string JWT_SECRET=your_secret_key
- Create a
-
Run the application:
npm start
The server will run at http://localhost:3000.
- Visit
/to browse blog posts. - Visit
/adminto log in as an admin (you may need to register a user first). - Use the dashboard to add, edit, or delete posts.
.
├── index.js # Application entry point
├── server/
│ ├── config/db.js # Database connection logic
│ ├── models/Post.js # Mongoose Post model
│ ├── routes/ # Application routes (main, admin)
├── views/ # EJS templates
├── public/ # Static assets (CSS, JS, images)
├── .env # Environment variables (not committed)
└── package.json
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
This project is open source and available under the MIT License.