- Table of Contents
- Introduction
- Features
- Folder Structure
- Prerequisites
- 🔧 Installation
- Scripts
- Dependencies
- Environment Variables
- Deployment Instructions
This project is a robust and flexible backend system designed to power e-commerce applications. It provides a solid foundation for building single vendor online store, managing products, handling user authentication, processing orders, and collecting customer reviews and feedback.
- Modular architecture for easy scalability and maintenance.
- User authentication and authorization.
- Secure password hashing using bcrypt.
- JSON Web Token (JWT) based authentication.
- CORS support for cross-origin requests.
- MongoDB database integration via Mongoose.
- Express.js for building RESTful APIs.
- Environment variables management with dotenv.
- Email sending capabilities (Nodemailer).
- API documentation using Swagger UI Express.
- Testing setup with Jest and Supertest.
- TypeScript support for improved code quality and maintainability.
Here is an overview of your project's folder structure:
.
├── .github/ # GitHub Actions workflow configuration
│ └── workflows/ # Workflow scripts
├── __tests__/ # Test files and test-related code
├── src/ # Source code directory
│ ├── App/ # Main application code
│ │ ├── modules/ # Modules for various features
│ │ │ ├── Auth/ # Authentication related code
│ │ │ ├── User/ # User management code
│ │ │ ├── Products/ # Product-related code
│ │ │ ├── Category/ # Category-related code
│ │ │ ├── Orders/ # Order management code
│ │ │ └── Review/ # Review and feedback code
│ ├── Config/ # Configuration files
│ ├── Middlewares/ # Express middlewares
│ ├── Routes/ # API route definitions
│ ├── Utils/ # Utility functions and modules
│ ├── app.ts # Main application entry point
│ └── index.ts # Application startup script
├── .env # Environment variables configuration
├── package.json # Project dependencies and scripts
└── README.md # Project documentation (you are here)
Before start to work must read this documentation - Backend documentation
List the prerequisites and dependencies that users need to have installed to run your application. For example:
Provide step-by-step instructions on how to install and set up your application locally. For example:
- Clone the ecommerce-backend repository:
git clone https://github.com/dtal/dreamfurniturebd-backend
- Change to the project directory:
cd dreamfurniturebd-backend
- Install the dependencies:
npm install
-
Create a
.env
file in the root directory of the project. -
Add your environment variables to the
.env
file. Here's an example with placeholders:PORT=5000 MONGO_URI=mongodb://localhost:27017/your-database NODE_ENV=development BCRYPT_SALTROUND=12 JWT_ACCESSTOKEN_SECRET=your-secret-key JWT_ACCESSTOKEN_EXP=1h JWT_REFRESHTOKEN_SECRET=your-refresh-secret-key JWT_REFRESHTOKEN_EXP=7d // follow env.example file for all
Replace the placeholders with your actual values.
start
: Build and start the application in production mode.dev
: Start the development server with automatic restart using nodemon.build
: Run tests, build TypeScript code, and generate TypeScript aliases.test
: Run tests using Jest.
- bcrypt: Password hashing library.
- cors: Cross-origin resource sharing middleware.
- dotenv: Environment variableList management.
- express: Web framework for Node.js.
- jsonwebtoken: JSON Web Token (JWT) library.
- mongoose: MongoDB object modeling for Node.js.
- nodemailer: Email sending library.
- swagger-ui-express: Swagger UI for API documentation.
- yamljs: YAML to JSON parser.
- zod: TypeScript-first schema validation library.
PORT
: The port on which the application will listen.MONGO_URI
: MongoDB connection URL.NODE_ENV
: Node.js environment (e.g., development, production).BCRYPT_SALTROUND
: Number of bcrypt salt rounds.JWT_ACCESSTOKEN_SECRET
: Secret key for JWT access tokens.JWT_ACCESSTOKEN_EXP
: Expiration time for JWT access tokens.
To deploy your Node.js application using GitHub Actions, follow these simplified steps:
-
Push Changes to GitHub: Make changes to your Node.js application code as needed.
-
Commit Changes: Commit your changes to the
main
branch.git add . git commit -m "Update application code"
-
Push to GitHub: Push the committed changes to your GitHub repository.
git push origin main
-
GitHub Actions: GitHub Actions will automatically trigger a workflow when changes are pushed to the
main
branch. This workflow performs the following tasks:- Builds your Node.js application.
- Pushes a Docker image to Docker Hub.
- Deploys the updated application to your server.
-
Monitor Deployment: Monitor the GitHub Actions workflow progress on your GitHub repository's Actions tab. The workflow will display the status of each step, including building, pushing, and deploying.
-
Access Deployed Application: Once the workflow is completed successfully, your Node.js application should be deployed and accessible. You can access it via the specified URL or domain name.
That's it! Your application is automatically deployed whenever you push changes to the main
branch of your GitHub
repository. This streamlined process minimizes manual deployment steps for users.
Please ensure that you have configured the required secrets (
e.g., DOCKER_USERNAME
, DOCKER_PASSWORD
, HOST
, USERNAME
, PASSWORD
, PORT
) in your GitHub repository's secrets
settings for the workflow to work correctly and in workflows docker-push.yml
change the docker image name
and
the script
(configure a script in your server that will trigger and redeploy your latest code).