An online shop with user comments
Online Shop uses Nodejs as Backend Language
Download and install Nodejs with this link :
https://nodejs.org/en/download
Online Shop uses MongoDB so install MongoDB
https://www.mongodb.com/docs/manual/installation/
Goto your IDE (I usually use Vscode and Webstorm) and clone the src
https://github.com/AsadiAhmad/Online-Shop.git
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
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
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;
if you have another formate of connection string you can replace it into uri
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")
Goto root path run this:
npm app.js