Skip to content

Alauddin-Dev-Bd/blogify-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blogify API (Backend)

This is the backend for the Blogify application, built with Node.js, Express, and Mongoose. It provides the RESTful API endpoints for managing blog posts.

🚀 Getting Started

Prerequisites

Make sure you have the following installed:

  • Node.js (v14 or higher)
  • pnpm
  • MongoDB Atlas account or a local MongoDB instance

Installation

  1. Clone the repository:

    git clone https://github.com/Alauddin-24434/blogify-backend.git
    cd blogify-backend
  2. Install the dependencies using pnpm:

    pnpm install

Configuration

Create a .env file in the root directory and add your MongoDB connection string.

.env


MONGO\_URI=your\_mongodb\_connection\_string
PORT=5000

Running the Server

Start the development server:

pnpm start

The server will be running at http://localhost:5000.


📂 Project Structure

This project follows an MVC-like architecture to ensure separation of concerns and maintainability.

.
├── src/
│   ├── app.ts                 # Main Express application setup
│   ├── server.ts              # Server entry point, connects to DB & starts app
│   └── app/
│       ├── controllers/       # Handles request/response logic and calls services
│       ├── routes/            # Defines API endpoints and links to controllers
│       ├── services/          # Contains business logic and interacts with models
│       ├── middlewares/       # Custom Express middleware functions
│       └── utils/             # Utility functions and helpers
├── .env                       # Environment variables
├── package.json               # Project dependencies and scripts
└── tsconfig.json              # TypeScript configuration

Key Components:

  • server.ts: The main entry point of the application. It handles the database connection and starts the Express server (app.ts).
  • app.ts: Configures the Express application, applies middleware, and sets up global routes.
  • app/controllers/: These files contain the logic for handling incoming requests and sending responses. They interact with services to perform business operations.
  • app/routes/: Defines the API routes (/posts, /posts/:id, etc.) and maps them to specific controller functions.
  • app/services/: Encapsulates the core business logic. Services interact directly with your MongoDB models (which would typically be in a models/ directory, implied by how services would use them) to perform CRUD operations and other data manipulations.
  • app/middlewares/: Contains custom Express middleware functions, e.g., for authentication, logging, error handling, etc.
  • app/utils/: A collection of utility functions that can be reused across different parts of the application.

📝 API Endpoints

Method Endpoint Description
GET /posts Get all blog posts
GET /posts/:id Get a single post
POST /posts Create a new post

About

This is the backend for the Blogify application, built with Node.js, Express, and Mongoose. It provides the RESTful API endpoints for managing blog posts.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors