0% found this document useful (0 votes)
17 views3 pages

Be 2.3

The document shows code for using an API with a backend technology. It includes code to connect to a MongoDB database using Mongoose, define a schema for student data, and use Express to build routes for an API including POST, GET, DELETE, and PUT requests. The API can create, read, update, and delete student documents from the MongoDB database. The learning outcomes are to understand how to use Node.js, build a website for an API, and use MongoDB and Mongoose.

Uploaded by

deadm2996
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Be 2.3

The document shows code for using an API with a backend technology. It includes code to connect to a MongoDB database using Mongoose, define a schema for student data, and use Express to build routes for an API including POST, GET, DELETE, and PUT requests. The API can create, read, update, and delete student documents from the MongoDB database. The learning outcomes are to understand how to use Node.js, build a website for an API, and use MongoDB and Mongoose.

Uploaded by

deadm2996
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Backend Technology

WORKSHEET 2.3
Student Name: Nidhi Yadav UID:22MCA20001
Branch: MCA Section/Group: 3(A)
Semester: 3rd semester Date: 28/10/2023

Que: Write a code that shows the use of API.


BackEnd:
Config.js:
mongoose = require('mongoose');
mongoose.connect("mongodb://127.0.0.1/stddata")

stdSchema.js:
const mongoose = require("mongoose"); const
mongodb = require("mongoose"); const stdSchema =
new mongoose.Schema({
Name: String,
Branch: String,
UID: String,
Section: String, }); module.exports = mongoose.model("stddtails",
stdSchema);

Post.js:

const express = require("express");


require("./config");
const stddtails = require("./schemaModel"); const app =
express();
app.use(express.json());

app.post("/create", async (req, res) => { let


data = req.body; let result = await
stddtails.create(data);
console.log("inserted");
res.send(result); });

app.get("/read", async (req, res) => { let data


= await stddtails.find(); res.send(data); });

app.delete("/del/:UID", async (req, res) => {


console.log(req.params);
let data = await stddtails.deleteOne({ UID: req.params.UID });
res.send(data); });
app.put("/update/:UID", async (req, res) => {
console.log(req.params);
let data = await stddtails.updateOne( {UID:"22MCA20592"},{ $set: req.body}); res.send(data); });
app.listen(4000);

Insert Data:

Read data:

Delete data:
Update data:

Learning Outcomes:
1.Able to understand how to use NODE JS.
2. Able to understand how to make website for API.
3. Learn how to use mongodb and mongoose.

You might also like