-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
executable file
·114 lines (86 loc) · 2.89 KB
/
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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const express = require('express');
const path = require('path');
const mongoose = require('mongoose');
const connectDB = require('./db/connection');
const response = require("./api/utils/response");
const { MongoClient } = require('mongodb');
const app = express();
const bodyParser = require('body-parser');
const URI = "mongodb+srv://sankhaJ:[email protected]/test?retryWrites=true&w=majority";
const Article = require('./api/models/article');
const PORT = process.env.PORT || 8080;
connectDB();
const routes = require("./api/routes");
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
//mongoose.connect("")
// mongoose
// .connect(
// "mongodb+srv://sankhaJ:[email protected]/test?retryWrites=true&w=majority",
// { useNewUrlParser: true, useUnifiedTopology: true }
// )
// .catch(err => response(res, null, 500, err));
// async function connectDB() {
// // await mongoose.connect(URI,{ useNewUrlParser: true, useUnifiedTopology: true });
// // console.log("connected to the cluster");
// const client = new MongoClient(URI, { useNewUrlParser: true, useUnifiedTopology: true });
// try {
// await client.connect();
// await listDatabases(client);
// } catch (e) {
// console.error(e);
// }
// };
// connectDB().catch(console.error);
// var test;
// async function listDatabases(client) {
// databasesList = await client.db().admin().listDatabases();
// console.log("Databases:");
// databasesList.databases.forEach(db => console.log(` - ${db.name}`));
// };
app.use("/", routes);
app.set('views',path.join(__dirname,'views'));
app.set('view engine','pug');
// app.get('/',async function(req,res){
// //res.send('Hello World');
// // var articles = [
// // {
// // id:1,
// // title:'Article One',
// // author:'Sankha Jayalath',
// // body:'This is article one'
// // },
// // {
// // id:2,
// // title:'Article Two',
// // author:'Shanika Waidyarathne',
// // body:'This is article two'
// // },
// // {
// // id:3,
// // title:'Article Three',
// // author:'Sameera Perera',
// // body:'This is article three'
// // }
// // ]
// Article.find({},function(err,articlesss){
// if(err){
// console.log(err);
// }
// else{
// res.render('index',{
// title:'Simple se',
// articles:articlesss
// });
// }
// });
// });
app.get('/articles/add',function(req,res){
res.render('add_article',{
title: 'Add Articles'
});
});
app.listen(PORT,function(){
console.log('Server started on port 8080')
console.log("heroku")
});