const express = require('express');
const app = express();
const port = 3000;


app.get("/", (req, res) => {
    res.end("Welcome to the home page");
})

app.get("/about", (req, res) => {
    res.end(`Welcome ${req.query.name}, you are ${req.query.age} years old`);
})

app.listen(port, () => {
    console.log(`Server running on port ${port}`)
})

// const myServer = http.createServer((req, res) => {
//     const log = `${format(new Date(), 'dd/MM/yyyy\tHH:mm:ss')} : ${req.method} '${req.url}' New Request Recieved\n`;
//     if (req.url === '/favicon.ico') return res.end();
//     const myUrl = url.parse(req.url, true);
//     console.log(myUrl);

//     fs.appendFile("log.txt", log, (err, data) => {
//         switch (myUrl.pathname) {
//             case "/":
//                 if (req.method == 'GET') res.end("Welcome on Home Page ");
//                 break;
//             case "/about": if (req.method == 'GET') res.end("About us");
//                 break;
//             case "/contact":
//                 const myContent = myUrl.query.name;
//                 const myAge = myUrl.query.age;
//                 res.end(`Hello ${myContent}....How are you! You are ${myAge} years old right?`);
//                 break;
//             case "/location": res.end("Location");
//                 break;

//             case "/signup": if (req.method == 'GET') res.end("Welcome to the signup page");
//             else if (req.method == 'POST') res.end("Thank you for sending the data");
//                 break;
//             default:
//                 res.end("404 Not Found");
//                 break;
//         }
//     })
// })

// myServer.listen(3000, () => {
//     console.log("Running successfuly on port 3000")
// })

