-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd2dad9
commit 8d702e6
Showing
3 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const express = require('express'); | ||
require ('./config'); | ||
const product = require('./product'); | ||
|
||
const app = express(); | ||
app.use(express.json()) //converts the data into JSON formate forom stream formate | ||
|
||
app.post("/create" , async (req,res)=>{ | ||
let data = new product(req.body); | ||
let result = await data.save(); | ||
console.log(result); | ||
res.send(result); | ||
}); | ||
|
||
const port= 8000; | ||
app.listen(port); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const mongoose = require('mongoose'); | ||
mongoose.connect("mongodb://localhost:27017/e-comm"); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//Here we define Schemas and Models | ||
|
||
const mongoose = require('mongoose'); | ||
|
||
//Schema | ||
const productSchema = new mongoose.Schema({ | ||
name:String, | ||
brand:String, | ||
price:Number, | ||
category:String | ||
}); | ||
|
||
//Model | ||
module.exports = mongoose.model('products' , productSchema); |