-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (49 loc) · 1.1 KB
/
index.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const express = require('express');
const mongoose = require('mongoose');
const dotenv = require('dotenv');
const cors = require('cors');
dotenv.config();
const app = express();
app.use(cors());
mongoose.connect(process.env.MONGODB_URI, {useNewUrlParser: true});
const videoSchema = new mongoose.Schema({
title: String,
thumbnail: String,
location: String,
duration: String,
views: {
type: Number,
default: 0
},
like: {
type: Number,
default: 0
},
dislike: {
type: Number,
default: 0
}
});
const Video = mongoose.model('Video', videoSchema);
Video.find().then(function(videos, err){
if(err){
// console.log(err);
}else{
app.get("/api", function(req,res){
res.send(videos);
});
}
});
// const video = new Video({
// title: "Vishal",
// thumbnail: "test",
// location: "works",
// duration: "00",
// views: 10,
// like: 50,
// dislike: 30
// })
// video.save();
app.listen(process.env.PORT || 5000, () => {
console.log(`Server listening on port ${process.env.PORT || 5000}`);
});