diff --git a/Lecture 3 - First Node Server/app.js b/Lecture 3 - First Node Server/app.js new file mode 100644 index 0000000..16ca8f1 --- /dev/null +++ b/Lecture 3 - First Node Server/app.js @@ -0,0 +1,10 @@ +const http = require('http'); + +const server = http.createServer((req, res) => { + console.log(req); +}); + +const PORT = 3001; +server.listen(PORT, () => { + console.log(`Server running on address http://localhost:${PORT}`); +}); \ No newline at end of file diff --git a/Lecture 4 - Request and Reponse/app.js b/Lecture 4 - Request and Reponse/app.js new file mode 100644 index 0000000..fea7fd9 --- /dev/null +++ b/Lecture 4 - Request and Reponse/app.js @@ -0,0 +1,32 @@ +const http = require('http'); + +const server = http.createServer((req, res) => { + console.log(req.url, req.method, req.headers); + + if (req.url === '/') { + res.setHeader('Content-Type', 'text/html'); + res.write(''); + res.write('Complete Coding'); + res.write('

Welcome to Home

'); + res.write(''); + return res.end(); + } else if (req.url === '/products') { + res.setHeader('Content-Type', 'text/html'); + res.write(''); + res.write('Complete Coding'); + res.write('

Checkout our products

'); + res.write(''); + return res.end(); + } + res.setHeader('Content-Type', 'text/html'); + res.write(''); + res.write('Complete Coding'); + res.write('

Like / Share / Subscribe

'); + res.write(''); + res.end(); +}); + +const PORT = 3001; +server.listen(PORT, () => { + console.log(`Server running on address http://localhost:${PORT}`); +}); \ No newline at end of file diff --git a/Lecture 4 - Request and Reponse/practise.js b/Lecture 4 - Request and Reponse/practise.js new file mode 100644 index 0000000..bc1eefb --- /dev/null +++ b/Lecture 4 - Request and Reponse/practise.js @@ -0,0 +1,48 @@ +const http = require('http'); + +const server = http.createServer((req, res) => { + console.log(req.url, req.method); + if (req.url === '/home') { + res.write('

Welcome to Home

'); + return res.end(); + } else if (req.url === '/men') { + res.write('

Welcome to Men

'); + return res.end(); + } else if (req.url === '/women') { + res.write('

Welcome to Women

'); + return res.end(); + } else if (req.url === '/kids') { + res.write('

Welcome to Kids

'); + return res.end(); + } else if (req.url === '/cart') { + res.write('

Welcome to Cart

'); + return res.end(); + } + + + res.write(` + + + Myntra + + + + + + + + `); + res.end(); +}); + +server.listen(3001, () => { + console.log('Server running on address http://localhost:3001'); +}); \ No newline at end of file diff --git a/Lecture 4 - Request and Reponse/temp.html b/Lecture 4 - Request and Reponse/temp.html new file mode 100644 index 0000000..0de4efe --- /dev/null +++ b/Lecture 4 - Request and Reponse/temp.html @@ -0,0 +1,19 @@ + + + + Myntra + + + + + + + \ No newline at end of file diff --git a/Lecture 4 - Request and Reponse/user.js b/Lecture 4 - Request and Reponse/user.js new file mode 100644 index 0000000..0fa2af1 --- /dev/null +++ b/Lecture 4 - Request and Reponse/user.js @@ -0,0 +1,42 @@ +const http = require('http'); +const fs = require('fs'); + +const server = http.createServer((req, res) => { + console.log(req.url, req.method, req.headers); + + if (req.url === '/') { + res.setHeader('Content-Type', 'text/html'); + res.write(''); + res.write('Complete Coding'); + res.write('

Enter Your Details:

'); + res.write('
'); + res.write('
'); + res.write(''); + res.write('') + res.write(''); + res.write(''); + res.write('
'); + res.write('
'); + res.write(''); + res.write(''); + return res.end(); + + } else if (req.url === '/submit-details' && + req.method === 'POST') { + fs.writeFileSync('user.txt', 'Prashant Jain'); + res.statusCode = 302; + res.setHeader('Location', '/'); + return res.end(); + } + res.setHeader('Content-Type', 'text/html'); + res.write(''); + res.write('Complete Coding'); + res.write('

Like / Share / Subscribe

'); + res.write(''); + res.end(); +}); + +const PORT = 3001; +server.listen(PORT, () => { + console.log(`Server running on address http://localhost:${PORT}`); +}); \ No newline at end of file diff --git a/Lecture 4 - Request and Reponse/user.txt b/Lecture 4 - Request and Reponse/user.txt new file mode 100644 index 0000000..eae7489 --- /dev/null +++ b/Lecture 4 - Request and Reponse/user.txt @@ -0,0 +1 @@ +Prashant Jain \ No newline at end of file