In this article we will be building an eCommerce platform with Node.js as backend and for frontend, we will have 3 different technologies (Angular, React and Vue.js). I will publish those articles and give link in this one soon.

We will break down this article into two parts, the backend and the frontend. Our application will have basic features like adding of product and adding product to cart.

Prerequisites

  • Familiarity with HTML, CSS, and JavaScript (ES6+).
  • Vs code or any code editor installed on your development machine.
  • Postman installed on your development machine.
  • Basic knowledge of React and Express.js.

We will start by setting up the backend for our application. Let’s create a new directory for our application and initialize a new Node.js application. Open up your terminal and type the following:

cd desktop
mkdir reactcart && cd reactcart
npm init -y
code .

Installing the necessary packages

We will have to install some packages for our application:

  • body-parser: is a piece of express middleware that reads a form’s input and stores it as a javascript object accessible through req.body.
  • nodemon : will watch our files for any changes and then restarts the server when any change occurs.
  • express will be used to build our Node.js server.
  • cors : is a mechanism that uses additional HTTP headers to tell browsers to give a web application running at one origin, access to selected resources from a different origin.
  • dotenv : will store all of our environment variables. This is where we will store our email variables.
  • morgan: is a package that will log all our application routes.
  • mongoose: an object modeling tool used to asynchronous query MongoDB.
  • multer: is a Node.js middleware for handling multipart/form-data, which is primarily used for uploading files.

To install this packages open your terminal and type:

npm i express mongoose morgan dotenv multer body-parser cors nodemon --save

Running this command will create a node_modules folder. You have to create a .gitignore file and add the node_modules file inside it.

#nodejs #web-development #javascript #node

Building a Shopping Cart in Node.js
7.40 GEEK