This repository was archived by the owner on Sep 24, 2024. It is now read-only.
forked from freeCodeCamp/boilerplate-express
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyApp.js
More file actions
81 lines (39 loc) · 1.21 KB
/
myApp.js
File metadata and controls
81 lines (39 loc) · 1.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
let express = require('express');
let app = express();
var bodyParser = require('body-parser');
require('dotenv').config();
console.log('Hello World');
app.use('/public', express.static(__dirname + '/public'));
app.use(function middleware(req, res, next){
console.log(req.method+' '+req.path+' '+'-'+' '+req.ip);
next();
});
app.get('/', function(req, res) {
res.sendFile(__dirname + '/views/index.html')
});
app.get('/json', function(req, res) {
process.env.MESSAGE_STYLE
if(process.env.MESSAGE_STYLE === 'uppercase'){
res.json({"message": "HELLO JSON"})
}
else{
res.json({"message": "Hello json"})
};
});
app.get('/now', function middleware(req,res,next){
req.time = new Date().toString();
next();
}, function (req, res){
res.json({"time": req.time});
});
app.get('/:word/echo', function(req,res){
res.json({"echo": req.params.word});
});
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
app.route('/name').get(function(req,res){
res.json({"name": req.query.first+" "+req.query.last})
}).post(function (req, res){
res.json({"name": req.body.first+" "+req.body.last});
});
module.exports = app;