-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
62 lines (51 loc) · 1.36 KB
/
app.js
File metadata and controls
62 lines (51 loc) · 1.36 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
// requires node modules express and morgan
const express = require('express');
const morgan = require('morgan');
// creating variable 'app' that renders our page using express
const app = express();
//connect db from index.js using sequelize
const models = require('./models');
// requiring routers
const userRouter = require('./routes/user')
const wikiRouter = require('./routes/wiki')
//verify that connection to db works
// db.authenticate().then(() => {
// console.log('connected to the database');
// });
// parses url-encoded bodies
app.use(express.urlencoded({ extended: false }));
// parses json bodies
app.use(express.json());
// adds the console.logs for each request
app.use(morgan('dev'));
// serves up static files from public folder
app.use(express.static(__dirname + '/public'));
// plugging in routers
app.use('/wiki', wikiRouter)
app.use('/user', userRouter)
const html = `
<!DOCTYPE html>
<html>
<head>
<title>Wikistack</title>
<link rel="stylesheet" href="/stylesheets/style.css" />
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
`;
// root directory will render the following
app.get('/', (req, res, next) => {
res.redirect('/wiki')
});
// async .sync mothod
const sync = async () => {
await models.db.sync();
};
sync({ force: true });
//port
const PORT = 3000;
app.listen(PORT, () => {
console.log(`App listening in port ${PORT}`);
});