-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpress.js
More file actions
29 lines (23 loc) · 739 Bytes
/
Copy pathexpress.js
File metadata and controls
29 lines (23 loc) · 739 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
const express = require('express');
const app = express();
app.use(express.static(__dirname + '/public'));
/* Structure of middleware and functions in express.js
Middleware can be used glabally or locally.
*/
const simpleLogger = (req, res, next) => {
console.log('${req.url} - ${req.method} - ${new Date().tooISOString()}');
const name = req.query.name;
if (name == 'Nayem') {
return res.json({ message: 'Bad Request'});
}
next();
};
// middleware for global;
app.use(simpleLogger);
// For global use app.use(simpleLogger);
app.get('/hello', simpleLogger, (req, res, next) => {
res.json({ message: 'Hello' });
});
app.listen(8000,() => {
console.log('Application running on port 8000');
});