const http = require('http');
const url = require('url');
const querystring = require('querystring');
const server = http.createServer((req, res) => {
if (req.method === 'GET') {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello from GET request');
} else if (req.method === 'POST') {
let body = '';
req.on('data', chunk => {
body += chunk.toString();
});
req.on('end', () => {
const postData = querystring.parse(body);
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello from POST request');
});
}
});
const port = 3000;
server.listen(port, () => {
console.log(`Server running on port ${port}`);
});