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
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
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 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) |
NewerOlder