Skip to content

An online shop with user comments with Nodejs And MongoDB

License

Notifications You must be signed in to change notification settings

AsadiAhmad/Online-Shop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Online-Shop

An online shop with user comments

Tech 🛠️ Languages and Tools :

HTML  CSS  JS  JQuery  nodejs  MongoDB 

Tutorial

Step1 : Install Nodejs

Online Shop uses Nodejs as Backend Language

Download and install Nodejs with this link :

https://nodejs.org/en/download

Step2 : Install MongoDB

Online Shop uses MongoDB so install MongoDB

https://www.mongodb.com/docs/manual/installation/

Step3 : Clone GitHub Repo

Goto your IDE (I usually use Vscode and Webstorm) and clone the src

https://github.com/AsadiAhmad/Online-Shop.git

Step4 : set your Nodejs Application

the src does'nt have any Nodejs configuration file

create New file named package.json in root of src with this lines :

{
  "name": "untitled",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "ejs": "^3.1.9",
    "express": "^4.19.2",
    "jquery": "^3.7.1",
    "jsonwebtoken": "^9.0.2",
    "mongodb": "^6.5.0",
    "mongoose": "^8.3.0",
    "multer": "^1.4.5-lts.1",
    "path": "^0.12.7"
  }
}

Goto your IDE terminall and type

npm install

with this command nodejs will install package-lock.json and set the configurations

Step5 : Install necessary Packages

Install all of the Packages with npm command

npm install ejs
npm install express
npm install jquery
npm install jsonwebtoken
npm install mongodb
npm install mongoose
npm install multer
npm install path

for checking installed packages you can run this command :

npm list

Step6 : Create Connection to MongoDB

I have gitignore my connection so you need create new connection file :

Create a Floder named Connection in /root/public/JS/BackEnd path

Create js file named connection.js like this :

const { MongoClient } = require('mongodb');
const uri = 'mongodb+srv://<user>:<password>@cluster-0-130.81jyjqx.mongodb.net/';
const dbName = 'OnlineShop';

let db;

async function connection() {
    if (!db) {
        const client = new MongoClient(uri, { useUnifiedTopology: true });
        await client.connect();
        db = client.db(dbName);
    }
    return db;
}

module.exports = connection;

Dont forget to replcae your username and password of your Mongo database here

if you have another formate of connection string you can replace it into uri

Step7 : Create MongoDB Datbase and collections :

create datbase named OnlineShop

commands used in MongoDB shell :

use OnlineShop

and Create these three collections :

use OnlineShop
db.createCollection("Comments")
db.createCollection("Products")
db.createCollection("users")

Step8 : Run the project :

Goto root path run this:

npm app.js

View