- CRUD Operations on Products
- EndPoint GET /api/v1/products
- CRUD Operations on Products
- EndPoint GET /api/v1/products/tags
- CRUD Operations on Products
- EndPoint POST /api/v1/products
More info and Testing in API Documentation
NodePop is a web application that allows users to buy and sell products. This README provides an overview of the application's features, setup, and usage.
NodePop offers the following features:
- User registration and authentication
- Product listing and browsing
- Product creation, editing, and deletion
- Add and Delete Products Likes
- User profile management
- User role management (admin, user, tester)
- User avatars and uploaded image handling
- Data population for tester users
- Application statistics tracking
- JWT-based authentication and authorization
- Rate limiting for API endpoints
- Swagger API documentation
Follow these steps to install NodePop on your system:
To get started, clone this repository to your local machine using the following command:
git clone https://github.com/JoseAlbDR/nodepop-fullstack.git
cd nodepop-fullstack
npm run setup-project
Before running the application, you need to configure environment variables in a .env
file. Copy and paste the following content into a file named .env
at the project's root and fill in the values as needed:
NODE_ENV=development_or_production
PORT=desired_port
MONGO_URL=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_key
JWT_EXPIRES_IN=jwt_duration(expample: 30d)
To start the NodePop application, run the following command:
If you want to run the app in development first make sure that NODE_ENV
env variable in .env
file is set to development
then run the following commands:
npm run setup-project
npm run dev
Navigate to http://locahost:5137
If you want to run the app in development first make sure that NODE_ENV
env variable in .env
file is set to production
then run the following commands:
First time build.
npm setup-production-build
npm start
Build once the server have been build at least one time. In order to backup users related data (avatar and products images) there is another script that you should run to rebuild the server once it has users/products with uploaded images.
npm rebuild-app
npm start
In both cases Navigate to http://locahost:3000
or whatever port you setup in .env file
NodePop uses cookies for user authentication and session management. When a user logs in, a JSON Web Token (JWT) is generated on the server and sent to the client as a cookie. This token contains information about the user's authentication status and session. The cookie is then included in subsequent requests to authenticate the user and maintain their session. It ensures that users don't have to re-enter their credentials for each request.
Users can create an account by navigating to the registration page and providing their name, email, password, and other optional information.
The provided information is validated on the server to ensure it meets the required criteria (e.g., valid email format, strong password).
During registration, NodePop automatically assigns a role to the user based on certain conditions. For example, the first registered user might be assigned the "admin" role, while subsequent users get the "user" role.
After validation, a new user account is created in the database. The user's password is securely hashed before storage.
A folder is created for the user (using their unique user ID) to store their files, such as avatars and uploaded images.
Upon successful registration, the user is issued a JWT token for authentication.
Users can log in by providing their registered email and password on the login page.
The provided credentials are validated on the server.
If the credentials are valid, NodePop checks the user's role. If the user's role is "tester," a database population process is triggered to create sample data.
Upon successful login, the user is issued a JWT token, which is sent to the client as a cookie for subsequent authentication.
General CRUD operations explained next, for all endpoints available in the API please refer to API Docs.
NodePop allows authorized users ("user" and "admin" roles) to perform CRUD operations on products.
Users can create a new product by providing product details such as name, price, image, and tags. Users may also upload an image for the product. Upon creation, the product is associated with the user who created it.
Users can view a list of all products. Additionally, users can view details of a specific product by clicking on its listing. The product details include its name, price, image, tags, and the user who created it.
Users can view a list of current unique TAGS within all the Products Stored in the Database.
Users can filter products based on specific criteria such as price range, availability (on sale or not), and tags. Filters can be applied using query parameters when fetching the list of products.
Example Query to Filter Products by Price Range (Min Price: 100, Max Price: 500):
/api/v1/products?price=100-500
Users can sort the list of products by different attributes, including name, price, and creation date. Sorting options are available as query parameters.
Example Query to Sort Products by Price in Ascending Order:
/api/v1/products?sort=lowest
When viewing a list of products, users can navigate through multiple pages of results. The pagination feature allows users to specify the page number and the number of items per page.
Example Query to Get the Second Page of Products with 10 Items per Page:
/api/v1/products?page=2&limit=10
For products with letter a
, that are on sale onSale=on-sale
, containing tag mobile tags=mobile
, sort by oldest products sort=oldest
, limited to 10 products per page limit=10
, showing the page 2 page=2
and in a 119 to 979 price range price=119-979
http://localhost:3000/api/v1/products?name=a&onSale=on+sale&tags=mobile&sort=oldest&limit=10&page=2&price=119-979
Users can update the details of a product they created. They can modify the name, price, image, tags, and other attributes. Users can also upload a new image for the product.
Users can delete a product they created. This action removes the product from the system.
Certain authorized users ("user" and "admin" roles) have the privilege to perform CRUD operations on user accounts.
Users can update the details of his account, including their name, email, role, and avatar. They can also change the user's password.
Users can delete his account including all associated data and files. This action is irreversible and permanently removes the user from the system.
Certain authorized users ("user" and "admin" roles) have the privilege to perform CRUD operations on product likes.
Users can Add a Like to a Product.
Users can Unlike a Product.
NodePop provides API documentation using Swagger. You can access the API documentation at http://localhost:3000/api/v1/docs when the application is running.
The folder structure of NodePop is organized as follows:
nodepop/
├── src/
│ ├── controllers/
│ ├── db/
│ ├── dtos/
│ ├── errors/
│ ├── middleware/
│ ├── models/
│ ├── public/
│ ├── routes/
│ ├── services/
│ ├── types/
│ ├── utils/
│ └── index.ts
├── .env
├── .gitignore
├── package.json
├── README.md
└── ...other project files