-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
98 lines (66 loc) · 2.21 KB
/
app.js
File metadata and controls
98 lines (66 loc) · 2.21 KB
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
const express= require('express');
const chalk=require('chalk');
const bodyParser=require('body-parser');
const mongoose=require('mongoose');
const cors=require('cors');
var path= require('path');
var app=new express();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
var nav=[{link:"/",title:'Home'},
{link:"/login",title:'LogIn'},
{link:"/signup",title:'SignUp'},
{link:"/books",title:'Books'},
{link:"/authors",title:'Authors'},
{link:"/books/add",title:'AddBooks'},
{link:"/authors/add",title:"AddAuthors"},
];
const booksRouter=require('./src/routes/bookRoutes')(nav);//passing nav to booksRouter
const authorRouter=require('./src/routes/authorRouter')(nav);
const signupRouter=require('./src/routes/signupRouter')(nav);
const loginRouter=require('./src/routes/loginRouter')(nav);
/* without view engine*/
// app.use(express.static(path.join(__dirname,"/public")));
// app.get('/',(req,res)=>{
// res.sendFile(path.join(__dirname,"/src/views/index.html"));
// });
// app.listen(3000,()=>{
// console.log("listening to port "+chalk.green('3000') );
// });
// app.get("/",(req,res)=>{
// res.send("First express app");
// });
// app.listen(3000,()=>{
// console.log("listening to port "+chalk.green('3000') );
// });
app.use(express.static(path.join(__dirname,"/public")));
app.use('/authors',authorRouter);
app.use('/books',booksRouter);
app.use('/login',loginRouter);
app.use('/signup',signupRouter);
mongoose.connect("mongodb+srv://unniDb:unni123@cluster0-3h7qw.mongodb.net/test?retryWrites=true&w=majority");
//mongoose.connect("mongodb://localhost:27017/Library");
var db=mongoose.connection;
db.on('error',(er)=>{
console.log(er)
})
db.once('open',()=>{
console.log("Success");
})
app.set('views','./src/views');
app.set('view engine','ejs');
// app.get('/',function(req,res){
// res.render('index.ejs',{list:['book1','book2','book3'],title:"Library"});
app.get('/',function(req,res){
res.render('index.ejs',
{
nav,
title:"Library"
}
)});
app.listen(process.env.PORT || 3000,()=>{
console.log("listening to port "+chalk.green('3000') );
})