This is a simple blogging platform API built with Express and Mongoose, following the MVC architecture. It includes endpoints for creating, reading, updating, and deleting blog posts.
- Create, read, update, and delete blog posts
- JSON responses with status messages
- Cross-Origin Resource Sharing (CORS) enabled
- API documentation generated with
apidoc
- Node.js (v14.x or higher)
- MongoDB 7 or higher
-
Clone the repository:
git clone https://github.com/anandpotukuchi/blogg-backend.git cd blogg-backend -
Install dependencies:
npm i -
Creating the variables:
cp env.example .env -
Run the application:
npm startThe server will start on
http://localhost:3000.
Generate the API documentation using apidoc:
-
Install
apidoc:npm install apidoc -gOr, if you prefer a local installation:
`` npm install apidoc --save-dev
-
Generate the documentation:
npx apidoc -i routes/ -o apidoc/If
apidocis installed globally, use:apidoc -i routes/ -o apidoc/ -
View the documentation:
The documentation will be generated in the
apidoc/directory. You can view it by navigating tohttp://localhost:3000/apidoc.
/blogg-backend
│
├── /controllers
│ └── postController.js
│
├── /models
│ └── Post.js
│
├── /routes
│ └── postRoutes.js
│
├── /views
│ └── posts.pug
│
├── /apidoc
│ └── [generated documentation]
│
├── app.js
├── package.json
├── .env
└── README.md
- GET /posts: Get all posts
- POST /posts: Create a new post
- GET /posts/:id: Get a post by ID
- PUT /posts/:id: Update a post by ID
- DELETE /posts/:id: Delete a post by ID
{
"title": "My First Blog Post",
"content": "This is the content of my first blog post. It contains valuable information and insights.",
"author": "John Doe"
}```