/*------add (start)----------*/ /*------add (end)----------*/

send data to database and read data from ui

 const express = require('express')

const app = express()
const port = 3000
const { MongoClient, ServerApiVersion } = require('mongodb');
const uri = "mongodb+srv://abcmehedi5:WD1kd4J7lElqvmJN@cluster0.mbjz2.mongodb.net/?retryWrites=true&w=majority";
// const password = 'WD1kd4J7lElqvmJN'

app.get('/' , (req , res) =>{
  res.sendFile(__dirname + '/index.html')
})

const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
client.connect(err => {
  const collection = client.db("organicdb").collection("products");
  // perform actions on the collection object
  const product = {name:"kodu" , price: 40 , quantity:5};
  collection.insertOne(product)
  .then((result) =>{
    console.log("product added sucessful")
  })
  // client.close();
});

app.listen(port,() =>{
  console.log("listen working")
})

No comments

Theme images by RBFried. Powered by Blogger.