JewelTest is a Node.js-based web application designed to manage users, products, categories, and currencies. It provides a robust backend API with features like user authentication, product management, and logging. The application is built with scalability and maintainability in mind, making it suitable for small to medium-sized e-commerce platforms or as a starting point for larger projects.
- Features
- Use Cases
- Project Structure
- Installation
- Usage
- Environment Variables
- Scripts
- Technologies Used
- Contributing
- User Authentication: Secure login and registration using JWT (JSON Web Tokens).
- Product Management: APIs to create, update, delete, and fetch products.
- Category Management: Manage product categories for better organization.
- Currency Management: Handle multiple currencies for product pricing.
- Order Management: APIs to manage user orders, including updates and status tracking.
- Static File Serving: Serve static assets like images from the
publicdirectory. - Logging: Detailed request logging using
morganand custom loggers. - Error Handling: Centralized error handling for consistent API responses.
- Environment Configuration: Use
.envfiles for secure configuration.
-
E-commerce Backend:
- Manage users, products, categories, and orders.
- Serve product images and other static assets.
- Handle user authentication and authorization.
-
API for Mobile or Web Applications:
- Provide a backend API for mobile or web apps to interact with product, user, and order data.
-
Learning Project:
- A great starting point for developers learning Node.js, Express, and backend development.
.env
.gitignore
app.log
database.js
index.js
package.json
server.js
controllers/
categories.js
currency.js
products.js
user.js
dummyData/
.env
addData.js
dummydata.js
dummydata.json
user_passwords.json
middlewares/
auth.js
cacheMiddleware.js
public/
images/
routes/
products.js
user.js
service/
auth.js
utils/
errorHandler.js
logger.js
redisClient.js
- controllers/: Contains logic for handling requests for categories, products, users, and currencies.
- dummyData/: Includes dummy data and scripts for populating the database.
- middlewares/: Contains middleware for authentication, caching, and other reusable logic.
- public/: Static assets like images.
- routes/: Defines API routes for products and users.
- service/: Contains reusable service logic, such as authentication.
- utils/: Utility functions for error handling, logging, and Redis caching.
-
Clone the repository:
git clone <repository-url> cd <repository-folder>
-
Install dependencies:
npm install
-
Set up the environment variables:
- Copy the
.envfile fromdummyData/.envto the root directory. - Update the variables as needed.
- Copy the
-
Start the server:
npm start
-
Access the API at:
http://localhost:<PORT> -
Use tools like Postman or cURL to interact with the API.
The following environment variables are required:
PORT: The port on which the server will run.DB_URL: The database connection string.JWT_SECRET: Secret key for JWT authentication.JWT_EXPIRES_IN: Expiration time for JWT tokens.JWT_COOKIE_EXPIRES: Expiration time for JWT cookies (in days).REDIS_URL: Redis connection string for caching.
-
Start the server:
npm start
-
Run in development mode:
npm run dev
-
Run tests (if applicable):
npm test
- Node.js: Backend runtime environment.
- Express.js: Web framework for building APIs.
- EJS: Template engine for rendering views.
- Morgan: HTTP request logger middleware.
- dotenv: Environment variable management.
- body-parser: Middleware for parsing request bodies.
- cookie-parser: Middleware for parsing cookies.
- Redis: In-memory data structure store for caching.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch:
git checkout -b feature-name
- Commit your changes:
git commit -m "Add feature-name" - Push to your branch:
git push origin feature-name
- Open a pull request.