Check if the following modules on there on your machine
- Nodejs
- MongoDb
- Nodemon
- yarn (preferable)
-
On OsX use the following commands
brew update brew install mongod mkdir -p /data/db sudo chown -R username /data/db
If you want to use coustom directory , then change
/data/db
todirectory/data/db
Then run
mongod
In a new tab. If custom directory is used then usemongod --dbpath=directory/data/db
-
On Linux based machines or windows machines, install related packages (.deb, or .rem or .exe)
Use the following commands for linux or macos based machines
sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_version_number| sudo -E bash -
For Linux based machines better option would be installing node using nvm. Enter the following command to install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
After nvm installed use
nvm install version_number
-
Run mongo deamon ( run mongodb service ) by using command
mongod
In some systems it might be
sudo systemctl start mongod
-
Install required packages for both frontend and backend.
cd be npm i cd ../fe npm i
-
Run backend
nodemon app.js #if you have nodemon already installed node app.js #works in any case
-
Run Frontend
yarn start # or npm run start
The database consists of three models. One for each of Products, Categories and Brand. Each of these has the following schema
-
Products
name: { type: String, required: true }, category: { type: String, required: true }, brand: { type: String, required: true }, price: { type: Number, required: true }, quantity: { type: Number, required: true }, description: { type: String, required: true }
-
Categories
name: { type: String, required: true }, parents: { type: [String], required: true, }, children: { type: [String], required: true }
The folder structure for backend look like
be
├── app.js
├── package.json
├── node_modules
├── controllers
└── auth
├── login.js
└── signup.js
└── products
├── addProduct.js
├── getBrand.js
├── validateCategory.js
└── getCategory.js
├── models
├── products.js
└── users.js
├── routes
└── products.js
The forlder structure for frontend looks like
fe
├── package.json
├── yarn.lock
├── node_modules
├── public
├── favicon.ico
├── index.htmk
├── logo.png
├── manifest.json
└── robots.txt
├── src
├── Components
├── addCategory.js
├── addProduct.js
├── home.js
└── nav.ja
├── App.css
├── App.js
├── index.css
├── index.js
├── setupTests.js
└── serviceWorker.js