The NodeJs Blog platform is designed for simplicity and ease of use. It's perfect for anyone looking to set up a quick and efficient blog. The backend is built with Node.js and Express, with MongoDB handling data storage. EJS is used as the templating engine to render dynamic content on the frontend.
- Post Creation & Viewing: Users can view blog posts on the homepage, and admins can create new posts.
- Static Pages: Includes an About page and a Contact page for additional site information.
- Admin Dashboard: Admins can log in to access a dashboard where they can manage all blog posts, including creating, editing, and deleting posts.
- Secure Authentication: Admin sessions are managed securely with a token-based authentication system and cookies.
The project is organized into several key directories and files:
nodejs-blog/
├── views/
│ ├── admin/
│ │ ├── add-post.ejs
│ │ ├── dashboard.ejs
│ │ ├── edit-post.ejs
│ │ └── index.ejs
│ ├── layouts/
│ │ ├── main.ejs
│ │ └── admin.ejs
│ ├── partials/
│ │ ├── footer.ejs
│ │ ├── header_admin.ejs
│ │ ├── header.ejs
│ │ └── search.ejs
│ ├── about.ejs
│ ├── contact.ejs
│ ├── home.ejs
│ ├── post.ejs
│ └── search.ejs
├── public/
│ ├── css/
│ │ └── style.css
│ ├── images/
│ │ ├── Blog-logo.png
│ │ ├── Hero Images.png
│ │ ├── img-noise-361x370.png
│ │ ├── instagram-logo.png
│ │ ├── Linkedin-logo.png
│ │ ├── search.png
│ │ └── X-logo.png
│ └── js/
│ └── script.js
├── server/
│ ├── config/
│ │ └── MongoDB.js
│ ├── helpers/
│ │ └── routeHelpers.js
│ ├── models/
│ │ ├── Post.js
│ │ └── User.js
│ └── routes/
│ ├── admin.js
│ └── main.js
To get started with the NodeJs Blog, follow these steps:
-
Clone the repository:
git clone https://github.com/yourusername/nodejs-blog.git cd nodejs-blog -
Install dependencies:
npm install
-
Set up your MongoDB connection:
- Update the MongoDB connection details in
config/MongoDB.js.
- Update the MongoDB connection details in
-
Start the application:
npm run start
- Homepage: View all blog posts available on the platform.
- Admin Access: Admins can log in to the dashboard to create, edit, or delete blog posts.
- Static Pages: Learn more about the blog on the About page or reach out via the Contact page.
The application employs a secure token-based authentication system that utilizes cookies to manage admin sessions. Here’s how it works:
- Login Process: When an admin logs in, a token is generated and stored as a cookie in the admin's browser. This token authenticates the admin and grants access to the dashboard and other restricted functionalities.
- Session Management: The token in the cookie is checked on each request to ensure that the user is authenticated. If the token is valid, the user is allowed access to admin features; if not, they are redirected to the login page.
- Security: The use of tokens and cookies ensures that only authenticated users can manage the blog's content, adding an essential layer of security to the platform.
Contributions are always welcome! If you'd like to contribute to the project, please fork the repository and submit a pull request with your changes.







