-
Notifications
You must be signed in to change notification settings - Fork 9
/
database.js
99 lines (63 loc) · 1.54 KB
/
database.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//jshint esversion:6
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
//mongoose.connect("",{ useUnifiedTopology: true,useNewUrlParser: true});
const app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.get("/",(req,res)=>{
res.send("Hello")
})
let port = process.env.PORT;
if (port == null || port == "") {
port = 3000;
}
app.listen(port, function() {
console.log("Server started on port 3000");
})
/*const blogSchema = {
title:{
type: String,
required: [true,"give a title"]
},
content:{
type: String,
required:[true,"add some content"]
}
}
const Blog = mongoose.model("Blog",blogSchema);
app.get("/",(req,res)=>{
Blog.find({},(err,posts)=>{
if(!err){
res.render("home",{
homeStartingContent:homeStartingContent,
posts:posts
});
}
});
})
app.post("/compose",(req,res)=>{
const postTitle = req.body.newTitle;
const postContent = req.body.newPost;
if(postTitle.length>0&&postContent.length>0){
const blog = new Blog({
title: postTitle,
content: postContent
});
blog.save((err)=>{
if(!err){
res.redirect("/");
}
});
}
})
app.get("/post/:postID",(req,res)=>{
const postID = req.params.postID;
Blog.findOne({_id:postID},(err,post)=>{
res.render("post",{
title: post.title,
content: post.content
})
});
})
*/