-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
37 lines (30 loc) · 806 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
36
37
var express = require('express'),
app = express(),
mongoose = require('mongoose'),
bodyParser = require('body-parser');
/*---APP CONFIG---*/
mongoose.connect("mongodb://localhost/DFM_Mockup_1");
app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(bodyParser.urlencoded({extended: true}));
/*---MONGOOSE / MODEL CONFIG---*/
var postSchema = new mongoose.Schema({
title: String,
description: String,
image: String,
created: { type: Date, default: Date.now }
});
var Post = mongoose.model("Post", postSchema);
/*---ROUTES---*/
app.get("/", function(req, res){
Post.find({}, function(err, posts){
if(err){
console.log(err);
} else{
res.render("index", {posts: posts});
}
});
});
app.listen("3000", function(){
console.log("App Running at Port 3000");
});