-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.ts
More file actions
38 lines (33 loc) · 1002 Bytes
/
app.ts
File metadata and controls
38 lines (33 loc) · 1002 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
import express from 'express';
import {db} from './config/db';
import {Router} from './routes/crudRoutes';
const app: any = express();
const PORT: number = 3000;
db.authenticate()
.then(() => {
console.log("Connection established ....");
}).catch(connectionErr => {
console.log("Error in connection => " + connectionErr);
});
app.use(express.json()); // for parsing json in request
app.use('/crud',Router);
app.use((req:any, res:any) => {
// Invalid request
res.json({
error: {
'name':'Error',
'status':404,
'message':'Invalid Request',
'statusCode':404,
'stack':'http://localhost:3000/'
},
message: 'Testing!'
});
});
db.sync()
.then(() => {
// start the Express server
app.listen( PORT, () => {
console.log( `server started at http://localhost:${ PORT }` );
});
}).catch(dbSyncErr => console.log("Error while db syncing => "+ dbSyncErr));