1.0.8 • Published 11 months ago
blog-backend-express v1.0.8
blog-backend-express
A versatile and efficient backend solution designed for managing blogs with Express.js.
Required Dependencies
To ensure proper functionality, install the following dependencies in your project:
expresspgpg-hstoresequelizedotenv
Environment Configuration
Set up the following environment variables in your .env file and update them according to your database configuration:
- DB_HOST: Database host (e.g.,
localhost) - DB_PORT: Database port (e.g.,
5432) - DB_NAME: Name of your database (e.g.,
test) - DB_USER: Database username (e.g.,
postgres) - DB_PASSWORD: Database password (e.g.,
root)
Usage
To use the blog-backend-express package in your project, follow these steps:
Import the package and set up the routes in your Express application:
const blogRoutes = require('blog-backend-express'); app.use('/api/blogs', blogRoutes);Access this like
http://localhost:3001/api/blogs1.http://localhost:3001/api/blogs-> with get method to fetch the blogs.2. `http://localhost:3001/api/blogs` -> with **POST** methods including **JSON** body to create.`eg : { "title": "How to create server in expressjs?", "content":"These are the following steps to create a expressjs server...", "author" :"John Doe"}`.
3. `http://localhost:3001/api/blogs/id` -> with **GET** method replace with blog id to fetch by id. 4. `http://localhost:3001/api/blogs/id` -> with **PUT** method to to update including JSON body. 5. `http://localhost:3001/api/blogs/id` -> with **DELETE** method to delete by blog id.