-
Notifications
You must be signed in to change notification settings - Fork 200
/
Copy pathserver.js
32 lines (27 loc) · 827 Bytes
/
server.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
// Import required modules
const express = require('express');
// Create an Express application
const app = express();
// Middleware function to log requests
app.use((req, res, next) => {
console.log(`Received a ${req.method} request to ${req.url}`);
next(); // Call next() to move to the next middleware or route handler
});
// Middleware function to check if the request contains a specific header
app.use((req, res, next) => {
if (req.headers.authorization) {
console.log('Authorization header present');
} else {
console.log('Authorization header not present');
}
next();
});
// Route handler
app.get('/', (req, res) => {
res.send('Hello, World!');
});
// Starting the server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});