forked from mattwc93/wikistack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
39 lines (32 loc) · 784 Bytes
/
Copy pathapp.js
File metadata and controls
39 lines (32 loc) · 784 Bytes
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
const express = require('express');
const morgan = require('morgan');
const views = require('./views/index');
const layout = require('./views/layout');
const { db } = require('./models');
const path = require('path');
let app = express();
let port = 3000;
app.use(morgan('dev'));
app.use(express.static(path.join(__dirname, '/public')));
const init = async () => {
try {
await db.sync();
app.listen(port, () => {
console.log(`connected to server on port ${port}`);
});
} catch (error) {
console.error('init error: ', error);
}
}
app.get('/', (req, res, next) => {
try {
res.send(layout('Hello World!'));
} catch (error) {
next(error);
}
});
db.authenticate().
then(() => {
console.log('connected to the database');
});
init();