Skip to main content
  1. All Posts/

mern-ecommerce

eCommerce JavaScript

mern-ecommerce

Frontend-> React JS

Backend-> Node JS & Express JS

Database-> MongoDB

Installation process

  1. clone the repo using this command

    <pre>git clone https://github.com/ashraf-kabir/mern-ecommerce.git</pre>
    
  2. install npm packages

    <ol dir="auto">
      <li>
        install backend packages
      </li>
    </ol>
    
    <pre>cd mern-ecommerce
    

    npm install

    <ol start="2" dir="auto">
      <li>
        install frontend packages
      </li>
    </ol>
    
    <pre>cd client
    

    npm install

  3. go to the parent folder of mern-ecommerce & create .env for connection, JWT_SECRET, BRAINTREE_MERCHANT_ID, BRAINTREE_PUBLIC_KEY and BRAINTREE_PRIVATE_KEY.

    cd mern-ecommerce
    sudo nano .env
    <p>
      (ctrl+x to save & nano follow instruction there)
    </p>
    
    <h5 dir="auto">
      <a rel="nofollow noopener" target="_blank" id="user-content-sample-code-for-backend-env" class="anchor" aria-hidden="true" href="#sample-code-for-backend-env"></a>sample code for backend .env
    </h5>
    
    <pre>MONGODB_URI=YOUR_MONGODB_URI
    

    JWT_SECRET=YOUR_JWT_SECRET BRAINTREE_MERCHANT_ID=YOUR_BRAINTREE_MERCHANT_ID BRAINTREE_PUBLIC_KEY=YOUR_BRAINTREE_PUBLIC_KEY BRAINTREE_PRIVATE_KEY=YOUR_BRAINTREE_PRIVATE_KEY

  4. create another .env file inside client directory for REACT_APP_API_URL.

    cd mern-ecommerce/client
    sudo nano .env
    <h5 dir="auto">
      <a rel="nofollow noopener" target="_blank" id="user-content-sample-code-for-frontend-env" class="anchor" aria-hidden="true" href="#sample-code-for-frontend-env"></a>sample code for frontend .env
    </h5>
    
    <pre>REACT_APP_API_URL=YOUR_API_URL</pre>
    
    <h5 dir="auto">
      <a rel="nofollow noopener" target="_blank" id="user-content-instructions" class="anchor" aria-hidden="true" href="#instructions"></a>Instructions:
    </h5>
    
    <ol dir="auto">
      <li>
        for mongodb atlas database creation follow this tutorial-><a rel="nofollow noopener" target="_blank" href="https://www.youtube.com/watch?v=KKyag6t98g8">https://www.youtube.com/watch?v=KKyag6t98g8</a>
      </li>
      <li>
        you can use any random string as JWTSECRET
      </li>
      <li>
        for localhost REACT_APP_API_URL is <a rel="nofollow noopener" target="_blank" href="http://localhost:5000/api">http://localhost:5000/api</a><br /> but for heroku (server deployment) it will be different
      </li>
      <li>
        <h4 dir="auto">
          <a rel="nofollow noopener" target="_blank" id="user-content-note-add-env-on-gitignore" class="anchor" aria-hidden="true" href="#note-add-env-on-gitignore"></a>note: add .env on .gitignore
        </h4>
      </li>
      
      <li>
        for server deployment use secrets directly
      </li>
    </ol>
    
  5. deploy this project on your local server by using this command

    cd mern-ecommerce
    npm run dev
    <h4 dir="auto">
      <a rel="nofollow noopener" target="_blank" id="user-content-note-both-backend--frontend-server-will-start-at-once-with-the-above-command" class="anchor" aria-hidden="true" href="#note-both-backend--frontend-server-will-start-at-once-with-the-above-command"></a>note: both backend & frontend server will start at once with the above command.
    </h4>
    
  6. Database Structure: (Table: columns)

    <ol dir="auto">
      <li>
        categories: _id, name, createdAt, updatedAt;
      </li>
      <li>
        orders: _id, status, products (Array), transaction_id, amount, address, user (Object), createdAt, updatedAt
      </li>
      <li>
        products: _id, photo (Object), sold, name, description, price, category, shipping, quantity, createdAt, updatedAt
      </li>
      <li>
        users: _id, role, history (Array), name, email, salt, hashed_password, createdAt, updatedAt
      </li>
    </ol>
    

App Description:

1. user can view all products
2. user can view single product
3. user can search products and view products by category and price range
4. user can add to cart checkout products using credit card info
5. user can register & sign in
6. admin can create, edit, update & delete products
7. admin can create categories
8. admin can view ordered products
9. admin can change the status of a product (processing, shipped, delivered, etc.)
  1. Deployed on https://ecommerce-ak.herokuapp.com/
  2. raise a star to support me