Node JS

Nodejs Mongodb Cloud Crud Application

This tutorial will teach you how to make Crud Application using Nodejs Mongodb Cloud Crud Application.

Create the Node Js Project Type on type command prompt

npm init

and press enter key.after that you have the fill configation of project.after done stuff you
will get the package.json file.

after that you have to install the following dependencies

npm i Express
npm i body-parser
npm i mongoose

After done the stuff you have to create the file index.js

index.js

const express = require("express")
const mongoose = require("mongoose")
var routers = require('./routes/routes');
const bodyParser = require("body-parser")

const app = express()

const port = 5000;

const mongodatabaseURL ="mongodb+srv://kobiram:mongoabc@cluster0.cqfkrbj.mongodb.net/?retryWrites=true&w=majority";

mongoose.connect(mongodatabaseURL,{
    useNewUrlParser: true,
    useUnifiedTopology: true
});

const connection = mongoose.connection


app.listen(port,()=>{
    console.log("Server is running port" +port);
})


connection.once("open",()=>{
    console.log("MongoDb Connected!!!......")
});


app.use(bodyParser.json());
app.use(routers);

 

routes.js

const express = require("express")
const router = express.Router();
var studentModel = require('../src/student/studentModel');


//Add Rrcords
router.post('/student/create', async(req,res)=>{
   
    const student = new studentModel(req.body)
    try{
            await student.save();
            res.status(201).send(
                {
                    "status" : true,
                    "message" : "Student Created!!!!!!!!!!!!!!!!"
                });
    }
    catch(error)
    {
        res.status(400).send(error);

    }


});

//View Records
router.get('/students', async(req,res)=>{
   
   try{

        const students = await studentModel.find({});
        res.send(students);
   }
   catch(error)
   {
        res.status(400).send(error);
   }

});


//find records

router.get('/students/:id', async(req,res)=>{
   
    try{
         const _id = req.params.id;
         const students = await studentModel.findById({_id});

        if(!students)
        {
            return res.status(404).send();
        }  
        return res.status(200).send(students); 
    }
    catch(error)
    {
         res.status(400).send(error);
 
    }

 
 });


//update records
 router.patch('/students/:id', async(req,res)=>{
   
    try{
        const _id = req.params.id;
        const body = req.body;
        const updatestudents = await studentModel.findByIdAndUpdate(_id,body,{new:true});

        if(!updatestudents)
        {
            return res.status(404).send();
        }  
     
        res.status(201).send(
            {
                "status" : true,
                "message" : "Student updateddd!!!!!!!!!!!!!!!!"
            });
 
    }
    catch(error)
    {
         res.status(400).send(error);
 
    }

 
 });


//delete records
 router.delete('/students/:id', async(req,res)=>{
   
    try{
            const _id = req.params.id;
        
         const deletestudents = await studentModel.findByIdAndDelete(_id);

        if(!deletestudents)
        {
            return res.status(404).send();
        }  
       
        res.status(201).send(
            {
                "status" : true,
                "message" : "Student Deletedd!!!!!!!!!!!!!!!!"
            });
    }
    catch(error)
    {
         res.status(400).send(error);
 
    }
 });

 

i have attached the video link below. which will do this tutorials step by step.

 

 

 

admin

Recent Posts

Employee Working Hours Calculation System using C#.net

Initialize the employee number, Hourswork,and Hoursrate to calculate a grosswage use the following condition. if…

1 week ago

Java Payroll System Calculate Employee Overtime

Act as a Java developer to create a program that calculates the gross wage for…

2 weeks ago

Employee Working Hours Calculation System using Java

Initialize the employee number, Hourswork,and Hoursrate to calculate a grosswage use the following condition. if…

2 weeks ago

Laravel 11 School Management System

In this tutorial, we will teach you how to create a simple school management system…

2 weeks ago

How to Make Admin Panel Using React MUI

I have design the Admin Basic templete using React MUI Design Admin Dashboard and Login.Here…

4 weeks ago

Install Laravel Breeze for Authentication Using Laravel 11

In this tutorial ,i am to going teach the Laravel Breeze.Laravel Breeze provides a simple…

1 month ago