This project implements a RESTful API with CRUD (Create, Read, Update, Delete) operations, utilizing PostgreSQL as the database and Sequelize as the ORM (Object-Relational Mapping) tool. The API is designed to manage resources stored in the PostgreSQL database, providing endpoints for creating, reading, updating, and deleting records.
2024-05-08.09-05-45.mp4
- Create new records in the database
- Retrieve existing records from the database
- Update existing records in the database
- Delete records from the database
- Node.js: JavaScript runtime environment
- Express.js: Web application framework for Node.js
- Sequelize: Promise-based ORM for Node.js
- PostgreSQL: Open-source relational database
- dotenv: Module for loading environment variables from a .env file
- Other dependencies: bcrypt, jsonwebtoken, nodemon (for development)
This project includes user authentication and role-based authorization capabilities. Users can authenticate using their credentials, and their access to certain endpoints is restricted based on their assigned role.
The following role types are available:
- Admin: Has full access to all endpoints and resources.
- User: Has limited access, typically to view or modify their own resources. You can assign roles to users during user registration or update their roles as needed.
- Clone the repository:
https://github.com/r-sarathi/postgres-rest-api.git
- Install dependencies:
cd postgres-rest-api
npm install
- Set up environment variables:
NODE_ENV = development
PORT = 3000
DB_USERNAME = your_database_username
DB_PASSWORD = your_database_password
DB_NAME = your_database_name
DB_HOST = localhost
DB_PORT = 5432
JWT_SECRET_KEY = your_secret_key
JWT_EXPIRES_IN = 1d
ADMIN_EMAIL = admin@example.com
ADMIN_PASSWORD = admin_password
- Run the development server:
npm run start:dev
The API endpoints can be accessed using HTTP requests. Here are some example requests:
- GET /api/posts: Retrieve all posts
- POST /api/posts: Create a new post
- GET /api/posts/:id: Retrieve a post by ID
- PUT /api/posts/:id: Update a post by ID
- DELETE /api/posts/:id: Delete a post by ID.
Contributions are welcome! Feel free to open issues or pull requests for bug fixes, improvements, or new features.