MONGODB
Sanni Ridwan
Posted on May 24, 2024
Create An Express Server Using Mongodb
Mongo db :
MongoDB is built on a scale-out architecture that has become popular with developers of all kinds for developing scalable applications with evolving data schemas. As a document database, MongoDB makes it easy for developers to store structured or unstructured data. It uses a JSON-like format to store documents.
Download Mongodb And Mongodb Compass:
Click here to download mongodb
Click here to download mongodb compass
Check Your Terminal If Mongodb Is Install Perfectly:
Check by typing mongosh on your terminal
Install MongoDb:
npm install mongodb on your vscode terminal
Create a database server
//call express and mongodb function
const express = require ("express");
const { MongoClient } = require ("mongodb");
const app = express();
// mongodb url
const url = "mongodb://localhost:27017";
const client = MongoClient(url);
// Create a database folder
const dataName = "Folder";
// Create a database collection
let dbCollection;
async function dbConnect() {
await client.connect();
console.log("connected to db successfully");
const db = client.db(dataName);
dbCollection = db.collection("Staff");
return "done .";
}
// Create a port number
const port = 3000;
app.listen(port, () => {
console.log(`Server is running on port http://localhost:${port}`);
})
RUN YOUR TERMINAL
💖 💪 🙅 🚩
Sanni Ridwan
Posted on May 24, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.