.js

.js
  const express=require(‘express’)
  const bodyParser= require(‘body-parser’)
  const mongoose= require(‘mongoose’)

  const app= express();

  app.use(bodyParser.urlencoded({extended:true}))
  app.use(bodyParser.json())

  app.get(‘/’,async(req,res)=>{
    console.log(req)
    res.sendFile(__dirname+’/MongoDB/index.html’)
  })

   
  app.post(‘/add-student’,async(req,res)=>{
    const {name,age,grade}=req.body
    console.log(name)
  })

  mongoose.connect(‘mongodb://localhost:27017/Yen’,{
    useNewUrlParser:true,
    useUndefinedTopology:true})
    .then(()=>(console.log(‘Succesfully connect’)))
    .catch(()=>{console.log(‘Not able to connect to data base’)})
  app.listen(9000, () => {
    console.log(‘server is listening at http://localhost:9000’)
  })
   
Scroll to Top