-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
45 lines (35 loc) · 895 Bytes
/
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
const express = require('express');
const app = express() //To set-up our application
const router = express.Router();
const path = __dirname + '/views/';
app.use(express.static(path));
app.use('/', router);
router.use(function (req,res,next) {
console.log('/' + req.method);
next();
});
router.get('/index', function(req,res){
res.sendFile(path + 'index.html');
});
router.get('/hello', function(req,res){
res.sendFile(path + 'hello.html');
})
//Error Handling
app.use((req, res, next) => {
const error = new Error('Not Found');
error.status = 404;
next(error);
});
app.use((error, req, res, next) => {
res.status(error.status || 500);
res.json({
error: {
message: error.message
}
});
});
//To start our server
app.listen(3000, () => {
console.log('My REST API Running on port 3000!');
})
app.timeout = 1000;