-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (28 loc) · 890 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require("body-parser");
const app = express();
app.use(bodyParser.urlencoded({extendend:false}));
app.use(express.json())
// Connect to MongoDB
mongoose.connect('mongodb://127.0.0.1:27017/API', { useNewUrlParser : true, useUnifiedTopology : true })
.then(() => console.log('Database connected'))
.catch((e) => console.log(e));
// File Schema
const fileSchema = new mongoose.Schema({
Name: String,
filepath: String,
uploadDate: { type: Date, default: Date.now },
});
const File = mongoose.model('file', fileSchema);
//create product
app.post("/api/post/new", async(req, res) =>{
const fileSchema = await fileSchema.create(req.body);
res.status(200).json({
success : true,
product
})
})
app.listen(4000, ()=>{
console.log("Server is working http://localhost:4000");
});