Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ramo4040/nodejs-exercise
This repository provides a collection of exercises designed to help you learn the fundamentals of Node.js web development using the Express framework.
https://github.com/ramo4040/nodejs-exercise
expressjs mongodb nodejs typescript
Last synced: 6 days ago
JSON representation
This repository provides a collection of exercises designed to help you learn the fundamentals of Node.js web development using the Express framework.
- Host: GitHub
- URL: https://github.com/ramo4040/nodejs-exercise
- Owner: ramo4040
- License: mit
- Created: 2024-06-16T17:47:47.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-29T16:23:37.000Z (3 months ago)
- Last Synced: 2024-08-30T02:59:05.691Z (3 months ago)
- Topics: expressjs, mongodb, nodejs, typescript
- Language: SCSS
- Homepage:
- Size: 9.29 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
SimpleCRM - Facturation en Ligne
**Overview**
SimpleCRM is a SaaS platform for online invoice management designed for businesses seeking a straightforward solution. The service offers a monthly subscription providing an all-in-one solution to simplify invoice management, accounting, and inventory control.
**Features**
* **Customer and Supplier Management:**
* Creation of detailed company profiles (name, address, tax information, etc.)
* Management of contact information
* **Product Management:**
* Creation of product profiles with purchase and sale prices, margins, sizes, etc.
* **Inventory Management:**
* Tracking of supplier replenishments
* **Invoicing:**
* Creation of invoices with one or multiple products
* Management of customer invoices
* **Order Management:**
* Tracking of supplier orders
* **Other Features:**
* Reporting and analysis
* Integration with accounting software**Business Rules**
* An invoice can contain one or more products.
* Each invoice is linked to a single customer.
* A product can be purchased from one or more suppliers.
* Each business can manage its invoices, customers, inventory, and suppliers.**User Stories**
* As a sales manager, I want to manage the list of customers, invoices, and orders (read, add, delete, modify).
**Goals**
* Modeling and creation of the database.
* Development of an API to manage the business activities of subscribed clients.**Technologies**
* **Web Server:** Node.js and Express
* **Database:** MySQL
* **ORM:** Prisma (recommended) or TypeORM## Installation and Startup
1. Clone the repository.
2. Install dependencies with `npm install`.
3. Start the server with `nodemon`.## Contribution
Contributions are welcome! Feel free to open issues or submit pull requests.
## License
This project is licensed under the MIT license.
jwt auth example
### JWT Authentication Example
Create a Node.js application that allows users to register, log in, and authenticate using JWT. Implement APIs for registration, login, and accessing a protected route using a well-organized project structure.
#### 1. Environment Variables 🔐
Create a `.env` file by copying the `.env.template` file and filling in the following environment variables:
```
PORT=3000
JWT_SECRET=
JWT_EXPIRE=DATABASE_URL="mysql://root:123456@localhost:3306/user"
MYSQLDB_USER="root"
MYSQLDB_ROOT_PASSWORD="123456"
MYSQLDB_DATABASE="user"
MYSQLDB_LOCAL_PORT=3307
MYSQLDB_DOCKER_PORT=3306NODE_LOCAL_PORT=3000
NODE_DOCKER_PORT=3000
```#### 3. Installation and Running
1. **Prerequisites:**
* **Docker and Docker Compose** installed.
* **Node.js and npm** installed.3. **Clone the repository:**
```bash
git clone https://github.com/ramo4040/NodeJs-Exercise.git
```
4. **Navigate to the project directory:**
```bash
cd NodeJs-Exercise
```
5. **Install dependencies:**
```bash
npm install
```
6. **Start the containers:**
```bash
docker-compose up --build -d
```
Or locally
```bash
npx prisma generate
npx prisma migrate dev --name init
npm run dev
```
This will build the Docker images if they don't exist and then run them in detached mode.
8. **Access the application:**
Open your browser and navigate to `http://localhost:3000` (or the port specified in your `.env` file).## Routes
### Register (/auth/register)
**Method:** POST
**Body:**
```json
{
"email": "your-email",
"password": "your-password"
}
```**Description:** Registers a new user by hashing the password and storing the user details.
### Login (/auth/login)
**Method:** POST
**Body:**
```json
{
"email": "your-email",
"password": "your-password"
}
```**Description:** Authenticates a user by verifying the password and generates a JWT if credentials are valid.
### Protected Route (/protected)
**Method:** GET
**Description:** Returns protected information if the JWT is valid.
JWT auth (MongoDB native-Mongoose)
# JWT Authentication Example
Create a Node.js application that allows users to register, log in, and authenticate using JWT. Implement APIs for registration, login, and accessing a protected route using a well-organized project structure.
## Routes
### Register (/auth/register)
**Method:** POST
**Body:**
```json
{
"email": "your-email",
"password": "your-password"
}
```**Description:** Registers a new user by hashing the password and storing the user details.
### Login (/auth/login)
**Method:** POST
**Body:**
```json
{
"email": "your-email",
"password": "your-password"
}
```**Description:** Authenticates a user by verifying the password and generates a JWT if credentials are valid.
### Protected Route (/protected)
**Method:** GET
**Description:** Returns protected information if the JWT is valid.
Restaurant Management API
# Restoran Chain Website Backend
This repository contains the backend code for the Restoran chain website, designed to improve the chain's marketing strategy and provide customers with an easy way to view meals, book tables, and learn more about the restaurant.
## Technologies Used
The backend is built using Node.js and Express, with a MySQL database and Prisma ORM. The template engine used is Ejs, and Nodemailer is used for sending emails, along with an email marketing service.
## Features
The backend includes the following features:
- Model and creation of the database
- Creation of necessary endpoints (Home, About, Contact, Meals, Send Email, Add Meal)
- Dynamic sections: meals, teams, restaurant coordinates of the Home page
- Sending a thank-you email to new newsletter subscribers
- Recording all necessary information about incoming requests in a text file## Business Rules
The following business rules are implemented in the backend:
- A meal can have only one category
- A restaurant can employ one or more employees
- A restaurant can serve one or more meals
- The restaurant offers its customers the opportunity to subscribe to its newsletter## Routes
| Method | Path | Description | Request Body | Response | Authentication |
|---|---|---|---|---|---|
| GET | `/` | Retrieves information for the home page (featured meals, team members, restaurant details) | N/A | JSON object containing home page data | N/A |
| GET | `/about` | Retrieves content for the "About Us" page | N/A | JSON object containing About content | N/A |
| GET | `/contact` | Retrieves content for the "contact Us" page | N/A | JSON object containing Contact content | N/A |
| POST | `/contact` | Handles submissions from the contact form | JSON object containing name, email, and message | Success message (200 OK) or error message (400 Bad Request) | N/A |
| POST | `/newsletter` | Handles newsletter subscription requests | JSON object containing email | Confirmation message (201 Created) or error message (400 Bad Request) | N/A |
| POST | `/admin/meals` | (Bonus) Handles submissions for adding new meals | JSON object containing meal details | Confirmation message (201 Created), error message (400 Bad Request), or 401 Unauthorized | Admin authentication required |
| POST | `/admin/employees` | (Bonus) Handles submissions for adding new employees | JSON object containing employee details | Confirmation message (201 Created), error message (400 Bad Request), or 401 Unauthorized | Admin authentication required |## Bonus Features
The following bonus features are also included:
- CSRF protection
- Table reservation
- Form to add meals
- Form to add employees
- Customization of the site to adapt it to each restaurant## Installation
To install the backend, follow these steps:
1. Clone the repository
2. Install the dependencies using `npm install`
3. Set up the MySQL database and update the `.env` file with the database credentials
4. Run the Prisma migrations using `npx prisma migrate dev`
5. Start the server using `npm start`## Contributing
Contributions are welcome! Please submit a pull request with any proposed changes.
## License
This project is licensed under the [MIT License](LICENSE).
MongoDB Native driver : REST API CRUD Operations for Users with Node.js, Express
This repository contains a basic example of a REST API built with Node.js, Express, and MongoDB's native driver to perform CRUD operations on a `users` collection.
## Getting Started
1. **Clone the repository:**
```bash
git clone https://github.com/your-username/users-api.git
```
2. **Install dependencies:**
```bash
npm install
```
3. **Create a `.env` file:**
```
MONGO_URI=mongodb://localhost:27017/your-database-name
PORT=8080
```
Replace `mongodb://localhost:27017/your-database-name` with your MongoDB connection string and `3000` with your desired port.
4. **Run the server:**
```bash
npm start
```
The server will start running at `http://localhost:3000`.## API Endpoints
The API provides the following endpoints for user management:
| Endpoint | Method | Description |
|--------------------|--------|------------------------------------------------------------------------------|
| `/users` | POST | Create a new user |
| `/users` | GET | Retrieve all users |
| `/users/:id` | GET | Retrieve a user by ID |
| `/users/:id` | PUT | Update a user by ID |
| `/users/:id` | DELETE | Delete a user by ID |## User Model
The user model is defined in `models/User.js` and includes the following fields:
- `username` (string, unique)
- `email` (string, unique)
- `password` (string, hashed)
- `role` (string, optional)
- `createdAt` (date)
- `updatedAt` (date)## Data Validation
Input data for each endpoint is validated against the user model schema to ensure consistency and data integrity.
## Error Handling
The API includes basic error handling mechanisms to catch and handle potential errors during database operations. Appropriate error messages are returned to the client in case of failures.
## Testing
The API can be tested using a tool like Postman or similar. You can send requests to the specified endpoints with valid or invalid data to verify the correct functionality of each CRUD operation.
## Further Improvements
- Implement authentication and authorization to secure the API.
- Add features like password reset or account verification.
- Implement pagination for handling large numbers of users.
- Implement more robust error handling and logging.## Contributing
Contributions are welcome! Please feel free to open issues or submit pull requests.
This project provides a basic foundation for building a user management API. You can extend it by adding more functionalities and features as required.