Build a Storefront Backend - Advanced Web Development egFWD - Second Project
This project was structured from scratch, with ZERO starter files.
To use this project, you need to follow the commands below:
-
Clone the repository into your local machine:
git clone https://github.com/ibrahimelmokhtar/ts-online-store-api.git
-
Redirect inside the cloned repository:
cd ts-online-store-api/
-
Install the required packages:
npm install
-
Copy
example.env
file into.env
file. -
Fill the created
.env
file with corresponding/appropriate information. -
For applying configured styling, run the following commands:
-
Prettier styling:
npm run prettier
-
ESLint styling:
npm run lint
-
-
For manipulating the database, run the following commands:
-
Run Up Migrations:
npm run migration:run
-
Run Down Migrations:
npm run migration:reset
-
-
For working on the development phase, run the following commands:
-
Live debugging while development:
npm run watch
-
Jasmine Testing:
npm run test
-
-
For working with the production phase, run the following commands:
-
Build the project:
npm run build
Then, Run the compiled server:
node build/server.js
-
OR simply, Start the server with one command:
npm run start
-
-
Open the local website on
http://127.0.0.1:5000/{endpoint}/{:queryParameters}
, more information about {endpoint} and {:queryParameters} will be explained in API Docmentation
(Back to top) This section will explain how the code works and how everything is put together.
This project has the structure shown below:
Project Structure
├─── docs/
├─── REQUIREMENTS.md
├─── migrations/
├─── sqls/
├─── 20220505125703-users-table-down.sql
├─── 20220505125703-users-table-up.sql
├─── 20220507132301-products-table-down.sql
├─── 20220507132301-products-table-up.sql
├─── 20220508135120-orders-table-down.sql
├─── 20220508135120-orders-table-up.sql
├─── 20220508135656-order-products-table-down.sql
├─── 20220508135656-order-products-table-up.sql
├─── 20220505125703-users-table.js
├─── 20220507132301-products-table.js
├─── 20220508135120-orders-table.js
├─── 20220508135656-order-products-table.js
├─── spec/
├─── support/
├─── jasmine.json
├─── src/
├─── config/
├─── env.config.ts
├─── server.config.ts
├─── constants/
├─── order.type.constant.ts
├─── orderProduct.type.constant.ts
├─── product.type.constant.ts
├─── unique.uuid.constant.ts
├─── user.type.constant.ts
├─── controllers/
├─── dashboard.controller.ts
├─── orderProducts.controller.ts
├─── orders.controller.ts
├─── products.controller.ts
├─── users.controller.ts
├─── database/
├─── __tests__/
├─── index.spec.ts
├─── index.ts
├─── helpers/
├─── guards/
├─── compare.ts
├─── encrypt.ts
├─── testing/
├─── reporter.ts
├─── middlewares/
├─── authentication.middleware.ts
├─── validation.middleware.ts
├─── models/
├─── __tests__/
├─── index.spec.ts
├─── order.model.spec.ts
├─── orderProduct.model.spec.ts
├─── product.model.spec.ts
├─── user.model.spec.ts
├─── order.model.ts
├─── orderProduct.model.ts
├─── product.model.ts
├─── user.model.ts
├─── routes/
├─── __tests__/
├─── dashboard.routes.spec.ts
├─── index.spec.ts
├─── orderProducts.routes.spec.ts
├─── orders.routes.spec.ts
├─── products.routes.spec.ts
├─── users.routes.spec.ts
├─── api/
├─── dashboard.routes.ts
├─── orderProducts.routes.ts
├─── orders.routes.ts
├─── products.routes.ts
├─── users.routes.ts
├─── index.ts
├─── schemas/
├─── orderProducts.schemas.ts
├─── orders.schemas.ts
├─── products.schemas.ts
├─── users.schemas.ts
├─── services/
├─── __tests__/
├─── dashboard.services.spec.ts
├─── dashboard.services.ts
├─── types/
├─── __tests__/
├─── index.spec.ts
├─── order.type.spec.ts
├─── orderProduct.type.spec.ts
├─── product.type.spec.ts
├─── user.type.spec.ts
├─── dashboard/
├─── ordersPerUser.type.ts
├─── productsInOrder.type.ts
├─── topProduct.type.ts
├─── order.type.ts
├─── orderProduct.type.ts
├─── product.type.ts
├─── user.type.ts
├─── server.ts
├─── .eslintrc
├─── .gitignore
├─── .prettierrc
├─── database.json
├─── example.env
├─── package.json
├─── README.md
├─── tsconfig.json
For more information about available endpoints, check this REQUIREMENTS.md file.
These packages are required to run this project smoothly without any errors.
These packages can be found in the "dependencies"
object inside the package.json
file.
- bcrypt - A bcrypt library for NodeJS.
- cors - Node.js CORS middleware.
- db-migrate - Database migration framework for node.js.
- db-migrate-pg - A postgresql driver for db-migrate.
- dotenv - Loads environment variables from .env file.
- express - Fast, unopinionated, minimalist web framework.
- express-validator - Express middleware for the validator module.
- helmet - Help secure Express/Connect apps with various HTTP headers.
- jsonwebtoken - JSON Web Token implementation (symmetric and asymmetric).
- morgan - HTTP request logger middleware for node.js.
- pg - PostgreSQL client.
- uuid - RFC4122 (v1, v4, and v5) UUIDs.
These packages can be found in the "devDependencies"
object inside the package.json
file.
- @types/bcrypt - TypeScript definitions for bcrypt.
- @types/cors - TypeScript definitions for cors.
- @types/express - TypeScript definitions for Express.
- @types/jasmine - TypeScript definitions for Jasmine.
- @types/jsonwebtoken - TypeScript definitions for jsonwebtoken.
- @types/morgan - TypeScript definitions for morgan.
- @types/pg - TypeScript definitions for pg.
- @types/supertest - TypeScript definitions for SuperTest.
- @types/uuid - TypeScript definitions for uuid.
- @typescript-eslint/parser - An ESLint custom parser which leverages TypeScript ESTree.
- eslint - An AST-based pattern checker for JavaScript.
- eslint-config-prettier - Turns off all rules that are unnecessary or might conflict with Prettier.
- eslint-plugin-prettier - Runs prettier as an eslint rule.
- jasmine - CLI for Jasmine, a simple JavaScript testing framework for browsers and Node.
- jasmine-spec-reporter - Spec reporter for jasmine behavior-driven development framework.
- prettier - Prettier is an opinionated code formatter.
- supertest - SuperAgent driven library for testing HTTP servers.
- tsc-watch - The TypeScript compiler with onSuccess command.
- typescript - TypeScript is a language for application scale JavaScript development.
- Documentation: HTTP Response Status Codes
- Documentation: db-migrate Module
- Documentation: node-postgres Module
- Documentation: bcrypt Module
- Documentation: JWT Module
- Documentation: Express-Validator Module
- Youtube Video: WebDevSimplified - What is JWT
- Youtube Video: WebDevSimplified - MVC Explained
- Youtube Video: Use Express-Validator Module with NodeJs
- Article: Arrays in PostgreSQL
- Article: How to Modify Arrays in PostgreSQL
- Article: How to use Code Blocks within Markdown Files