diff --git a/03. Data Structures/Queues/LEARN b/03. Data Structures/Queues/LEARN new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/03. Data Structures/Queues/LEARN @@ -0,0 +1 @@ + diff --git a/loggerMiddleware.js b/loggerMiddleware.js new file mode 100644 index 0000000..25925e8 --- /dev/null +++ b/loggerMiddleware.js @@ -0,0 +1,29 @@ +const express = require('express'); +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}`); +}); diff --git a/server.js b/server.js new file mode 100644 index 0000000..ec24f31 --- /dev/null +++ b/server.js @@ -0,0 +1,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}`); +});