Node.js E-Commerce API, a backend service for an e-commerce application. It provides endpoints for managing users, products, categories, and orders. The API is built with Node.js + TypeScript, Express, and MongoDB.
Project still under development.
- Node.js: JavaScript runtime environment used to execute server-side code.
- TypeScript: Allows specifying the types of data being passed around within the code.
- Express: Fast and minimalist web framework for Node.js.
- MongoDB: Non-relational document database for agile development.
- Mongoose: ODM (Object Data Modeling) library for MongoDB and Node.js to manage data.
node-ecommerce-api/
|── dist/...
|── node_modules/...
│── public/
│ ├── images/
│ ├── uploads/
│── src/
│ ├── config/
│ │ ├── dbConnection.js
│ │ ├── unProtectedPaths.js
| |
│ ├── controllers/
│ │ ├── categories.controller.js
│ │ ├── orders.controller.js
│ │ ├── products.controller.js
│ │ ├── users.controller.js
| |
│ ├── helpers/
│ │ ├── uploadImage.js
| |
| |── interfaces/
| | |── IEnvVariables.ts
| | |── IJwtPayload.ts
| | |── IMulterFilesRequest.ts
| | |── IMulterRequest.ts
| | |── IOrderItemRequest.ts
| |
| |── middlewares/
| | |── authJwt.ts
| |
│ ├── models/
| | |── interfaces/
| | | |── ICategory.ts
| | | |── IOrder.ts
| | | |── IOrderItem.ts
| | | |── IProduct.ts
| | | |── IUser.ts
| | |
│ │ ├── Category.model.js
│ │ ├── Order.model.js
│ │ ├── OrderItem.model.js
│ │ ├── Product.model.js
│ │ ├── User.model.js
| |
│ ├── routes/
│ │ ├── categories.routes.js
│ │ ├── orders.routes.js
│ │ ├── products.routes.js
│ │ ├── users.routes.js
| |
│ ├── utils/
│ │ ├── apiUrl.js
│ │ ├── validateEnvVariables.js
| |
│ ├── server.js
|
│── .env
│── .gitignore
│── LICENSE
│── package-lock.json
│── package.json
│── README.md
|── tsconfig.json
- Node.js (latest LTS version)
- MongoDB (local or cloud instance)
git clone https://github.com/MartinXCVI/node-ecommerce-api.git
cd node-ecommerce-api
npm install
Create a .env
file in the root directory and configure the following variables:
API_URL=/api/v1
DB_CONNECTION_STRING=mongodb+srv://<username>:<password>@<cluster_name>.cekcm.mongodb.net/<database_name>?retryWrites=true&w=majority&appName=<cluster_name>
SALT_ROUNDS=<number_of_rounds>
ACCESS_TOKEN_SECRET=<your_access_token_secret>
REFRESH_TOKEN_SECRET=<your_refresh_token_secret>
- Start the server:
npm start
- Start the server in development mode (with nodemon):
npm run dev
bcrypt
: Library for hashing passwords.body-parser
: Middleware to parse incoming request bodies.cookie-parser
: Middleware to parse cookies.cors
: Middleware to enable Cross-Origin Resource Sharing (CORS).dotenv
: Loads environment variables from a.env
file.express
: Minimalistic web framework for Node.js.express-jwt
: Middleware for handling JWT authentication.jsonwebtoken
: Library for generating and verifying JWTs.mongoose
: ODM for MongoDB to manage data.morgan
: HTTP request logger middleware.multer
: Middleware for handling file uploads.
These are development dependencies required to build, run, and maintain the project efficiently.
TypeScript needs type definitions for JavaScript libraries to enable static type checking.
@types/bcrypt
- Type definitions for thebcrypt
library (used for hashing passwords).@types/body-parser
- Type definitions forbody-parser
(middleware for parsing request bodies).@types/cookie-parser
- Type definitions forcookie-parser
(middleware for handling cookies).@types/cors
- Type definitions forcors
(middleware to enable Cross-Origin Resource Sharing).@types/express
- Type definitions forexpress
, ensuring type safety in request handling.@types/jsonwebtoken
- Type definitions forjsonwebtoken
(used for JWT authentication).@types/morgan
- Type definitions formorgan
(HTTP request logger middleware).@types/multer
- Type definitions formulter
(middleware for handling file uploads).@types/node
- Type definitions for Node.js, enabling TypeScript support for built-in modules.
nodemon
- Automatically restarts the server during development when files change.ts-node
- Allows running TypeScript files directly without needing a manual compilation step.typescript
- The TypeScript compiler, required to transpile.ts
files into JavaScript.
- Node.js latest documentation
- TypeScript documentation
- Nodemon project website
- Getting started with Express.js
- Dotenv repository
- MongoDB documentation
- Mongoose documentation
- bcrypt NPM package
- Multer repository
- body-parser NPM package
- cookie-parser NPM package
- Cross Origin Resource Sharing
- express-jwt NPM package
- JSON Web Tokens official website's introduction
- Morgan NPM package
This project is licensed under the MIT License.