This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import express from 'express' | |
| var app = express() | |
| var port = process.env.PORT || 8080 | |
| app.get("/", function (req, res){ | |
| res.send( "Welcome to Tutorial of REST API using MongoDB, ExpressJS and NodeJS"); | |
| }) | |
| app.listen(port) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import express from 'express' | |
| import mongoose from "mongoose" | |
| import Cors from 'cors' | |
| var app = express() | |
| var port = process.env.PORT || 8080 | |
| app.use(express.json()) | |
| app.use(Cors()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import mongoose from "mongoose" | |
| const CarsSchema = mongoose.Schema({ | |
| Name: String, | |
| Model: String, | |
| Price: String, | |
| meta: { | |
| Fuel_Type: String, | |
| Mileage: String, | |
| Seating_Capacity: Number |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.post("/Cars_add", function (req, res) { | |
| const dbfeed = req.body | |
| try { | |
| Cars.create(dbfeed, (err, data) => { | |
| if (err) { | |
| res.status(500).send(err) | |
| } | |
| else { | |
| res.status(201).send(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.get("/Cars", function (req, res) { | |
| try { | |
| Cars.find((err, data) => { | |
| if (err) { | |
| res.status(500).send(err) | |
| } | |
| else { | |
| res.status(200).send(data) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import express from 'express' | |
| import mongoose from "mongoose" | |
| import Cors from 'cors' | |
| import Cars from './Cars' | |
| var app = express() | |
| var port = process.env.PORT || 8080 | |
| app.use(express.json()) | |
| app.use(Cors()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "rest_api", | |
| "version": "1.0.0", | |
| "description": "Rest API using MEN (MongoDB,ExpressJs and NodeJs)", | |
| "main": "server.js", | |
| "type": "module", | |
| "scripts": { | |
| "test": "echo \"Error: no test specified\" && exit 1", | |
| "start": "nodemon server.js" | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| { | |
| "name": "Kia Sonet", | |
| "Model": "Sonet", | |
| "Price": "Rs. 6.79 - 13.19 Lakh", | |
| "meta":{ | |
| "Fuel_Type": "Petrol / diesel", | |
| "Mileage":"18.4 - 24.1 Kmpl", | |
| "Seating_Capacity": 5 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import mongoose from 'mongoose'; | |
| const UserDataSchema = mongoose.Schema({ | |
| Name: String, | |
| FName: String, | |
| Address: String, | |
| PhonNo: String, | |
| Email: String | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.get("/details", function (req, res) { | |
| UserDetails.find((err, data) => { | |
| if (err) { | |
| res.status(501).send(err) | |
| } | |
| else { | |
| res.status(200).send(data) | |
| } | |
| }) |
OlderNewer