This is a comprehensive blogging application with full CRUD (Create, Read, Update, Delete) functionalities. Users can sign up, sign in, add blogs, and comment on blogs. The application uses MongoDB for the database, JWT tokens for authentication, and EJS for server-side rendering.
- Features
- Technologies Used
- Prerequisites
- Installation
- Environment Variables
- Running the Application
- Project Structure
- Routes
- Middleware
- Models
- User Authentication (Sign Up, Sign In)
- Create, Read, Update, Delete (CRUD) functionalities for blogs
- Comment on blogs
- JWT-based authentication
- EJS for server-side rendering
- Secure password storage using hashing and salting
- Node.js
- Express.js
- MongoDB
- Mongoose
- JWT (JSON Web Tokens)
- EJS (Embedded JavaScript templating)
- dotenv
- Cookie-parser
- Crypto
Ensure you have the following installed on your local development machine:
- Node.js (>=14.x.x)
- npm (>=6.x.x)
- MongoDB
-
Clone the repository:
git clone https://github.com/yourusername/blogging-app.git cd blogging-app
-
Install the dependencies:
npm install
Create a .env
file in the root directory and add the following variables:
PORT=8000
MONGO_URL=your_mongo_connection_string
Replace your_mongo_connection_string
with your actual MongoDB connection string.
-
Start the MongoDB server if it's not already running:
mongod
-
Start the application:
npm start
-
Open your browser and navigate to:
http://localhost:8000
.
├── controllers
│ ├── user.js
│ ├── blog.js
├── middlewares
│ ├── authentication.js
├── models
│ ├── user.model.js
│ ├── blog.model.js
├── routes
│ ├── user.js
│ ├── blog.js
├── views
│ ├── home.ejs
│ ├── login.ejs
│ ├── register.ejs
│ ├── blog.ejs
├── public
│ ├── css
│ ├── js
├── .env
├── .gitignore
├── package.json
├── server.js
-
/user
GET /register
- Render registration pagePOST /register
- Handle user registrationGET /login
- Render login pagePOST /login
- Handle user loginGET /logout
- Handle user logout
-
/blog
GET /
- Get all blogsGET /:id
- Get blog by IDPOST /
- Create a new blogPUT /:id
- Update blog by IDDELETE /:id
- Delete blog by ID
checkForAuthenticationCookie
- Middleware to check for JWT authentication cookie
-
User
fullName
: String, requiredemail
: String, required, uniquesalt
: Stringpassword
: String, requiredprofileImageUrl
: String, default/images/default.png
role
: String, enum["USER", "ADMIN"]
, defaultUSER
-
Blog
title
: String, requiredbody
: String, requiredcoverImageUrl
: StringcreatedBy
: ObjectId, refuser
, required
For any issues or feature requests, please open an issue on the GitHub repository.