Skip to content

rana-arju/techBlog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Teach Blog - blogging backend

The Blog Project is a backend system for a blogging platform with Admin and User roles. Admins manage users and blogs, while Users can perform CRUD operations on their own blogs. Features include secure authentication, role-based access control, and a public API with search, sort, and filter functionalities. Built with TypeScript, Node.js, Express.js, and MongoDB, the project ensures security and efficiency.

Developer

Live API url

https://techblog-server.vercel.app/

or

https://techblog-server.vercel.app/

Video Explaination:

Tech-Blog

Technologies Used

  • TypeScript: Strong typing and enhanced developer experience.
  • Node.js: Runtime environment for JavaScript-based backend.
  • Express.js: Framework for building RESTful APIs.
  • MongoDB & Mongoose: NoSQL database with an ORM for schema validation and CRUD operations.

Environment Variables

To run this project, you will need to add the following environment variables to your .env file

DATABASE_URL= <Your database URL>
PORT= <Port number>
NODE_ENV = development

BCRYPT_SALT_ROUNDS=
JWT_ACCESS_TOKEN=
REFRESH_TOKEN=

JWT_ACCESS_EXPIRES =
REFRESH_ACCESS_EXPIRES =

Admin login crediential:

email: admin@gmail.com
password: admin1234

Installation

Install my-project with npm

You will need to download Git and Node to run this project

  • Node
  • Git
  • npm

Also check this out if you are new to node js.

node --version
git --version

Run Locally

Clone the project

  git clone https://github.com/rana-arju/techBlog.git

Go to the project directory

  cd techBlog

Install dependencies

  npm install

Start the server

  npm run dev

API Endpoint

Registration user

  POST /api/auth/register

User Example

Request Body:


{
  "name": "John Doe",
  "email": "john@example.com",
  "password": "securepassword"
}

Login User

  POST /api/auth/login

Get all Blogs with query or without

Example:

/api/blogs?search=technology&sortBy=createdAt&sortOrder=desc&filter=60b8f42f9c2a3c9b7cbd4f18
  GET /api/blogs

Post Blog (only login user can post blog)

  POST /api/blogs

Blog example:

Request Body:


{
  "title": "My First Blog",
  "content": "This is the content of my blog."
}

Delete own blog

  DELETE /api/blogs/:id

Update own single blog

  PATCH /api/blogs/:id

Blog example:

Request Body:


{
  "title": "Updated Blog Title",
  "content": "Updated content."
}

Admin Action API

Blocked any user

  PATCH /api/admin/users/:userId/block

Delete Users blog

  DELETE /api/admin/blogs/:id

Folder Structure πŸ“‚

β”œβ”€β”€ README.md
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ .env
β”œβ”€β”€ package-lock.json
β”œβ”€β”€ package.json
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ App.ts
β”‚   β”œβ”€β”€ server.ts
β”‚   └── app
β”‚      β”œβ”€β”€ config
β”‚      β”‚    └── index.ts
|      β”œβ”€β”€ builder
β”‚      β”‚    └── QueryBuilder.ts
|      β”œβ”€β”€ errors
β”‚      β”‚    └── error all files
|      β”œβ”€β”€ middleware
β”‚      β”‚    └── auth, globalErrorHandler,notFound and validationRequest file
β”‚      └── modules
β”‚         └── Admin
|         |    β”œβ”€β”€ admin.controller.ts
|         |    β”œβ”€β”€ admin.service.ts
|         |    β”œβ”€β”€ admin.route.ts
β”‚         └── Auth
|               β”œβ”€β”€ auth.controller.ts
|               β”œβ”€β”€ auth.schema.ts
|               β”œβ”€β”€ auth.interface.ts
|               β”œβ”€β”€ auth.service.ts
|               β”œβ”€β”€ auth.utils.ts
|               β”œβ”€β”€ auth.validation.ts
|               └── auth.route.ts
β”‚         └── Blog
|               β”œβ”€β”€ blog.controller.ts
|               β”œβ”€β”€ blog.schema.ts
|               β”œβ”€β”€ blog.interface.ts
|               β”œβ”€β”€ blog.service.ts
|               β”œβ”€β”€ blog.validation.ts
|               └── blog.route.ts
β”‚      └── routes
β”‚         └── index.ts
β”‚      └── utils
β”‚         └── catchAsync.ts and sendResponse.ts
β”‚
β”œβ”€β”€  vercel.json
β”œβ”€β”€  eslint.config.mjs
β”œβ”€β”€ .gitignore
β”œβ”€β”€ .prettierigmore
└── .prettierrc

Packages Used πŸ“¦

Used Package List
express js
mongoose
typescript
JWT
jsonWebToken
bcrypt
Zod
cors
dotenv
prettier
eslint__js

About

The Blog Project is a backend system for a blogging platform with Admin and User roles. Admins manage users and blogs, while Users can perform CRUD operations on their own blogs. Features include secure authentication, role-based access control, and a public API with search, sort, and filter functionalities. Built with TypeScript, mongoose Express

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors