├── package.json ├── index.js ├── index.html ├── .gitignore └── contact.html /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "my-folder", 3 | "version": "1.0.0", 4 | "description": "fynd assignment exercise 1", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Krithik Suvarna", 10 | "license": "ISC" 11 | } 12 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const http = require("http"); 2 | const fs = require("fs"); 3 | const url = require("url"); 4 | const path = require("path"); 5 | const qs = require("querystring"); 6 | 7 | const server = http.createServer(); 8 | 9 | server.on("request", async (req, res) => { 10 | const parts = url.parse(req.url, true); 11 | 12 | res.writeHead(200, { "content-type": "text/html" }); 13 | switch (parts.pathname) { 14 | case "/message": 15 | if (req.method === "POST") { 16 | const buffers = []; 17 | for await (const chunk of req) { 18 | buffers.push(chunk); 19 | } 20 | const data = Buffer.concat(buffers).toString(); 21 | const message = qs.parse(data); 22 | const ws = fs.createWriteStream(path.join(__dirname, "messages.json"), { 23 | flags: "a+", 24 | }); 25 | ws.write(JSON.stringify(message)); 26 | } 27 | case "/contact": 28 | const rs = fs.createReadStream( 29 | path.join(__dirname, "contact.html"), 30 | "utf-8" 31 | ); 32 | rs.pipe(res); 33 | break; 34 | default: 35 | const rs1 = fs.createReadStream( 36 | path.join(__dirname, "index.html"), 37 | "utf-8" 38 | ); 39 | rs1.pipe(res); 40 | } 41 | }); 42 | 43 | server.on("error", (error) => { 44 | console.error(error.message); 45 | }); 46 | 47 | server.listen(3000); 48 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 11 | 14 | 17 | 18 | 19 | 20 | 21 | 37 |
38 |
39 |
About Me
40 |

Hi! I am Krithik Suvarna. I am a final year student studying at SIESGST, Nerul

41 |
42 |
43 | 44 | 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | messages.json 2 | # Logs 3 | logs 4 | *.log 5 | npm-debug.log* 6 | yarn-debug.log* 7 | yarn-error.log* 8 | lerna-debug.log* 9 | .pnpm-debug.log* 10 | 11 | # Diagnostic reports (https://nodejs.org/api/report.html) 12 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 13 | 14 | # Runtime data 15 | pids 16 | *.pid 17 | *.seed 18 | *.pid.lock 19 | 20 | # Directory for instrumented libs generated by jscoverage/JSCover 21 | lib-cov 22 | 23 | # Coverage directory used by tools like istanbul 24 | coverage 25 | *.lcov 26 | 27 | # nyc test coverage 28 | .nyc_output 29 | 30 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 31 | .grunt 32 | 33 | # Bower dependency directory (https://bower.io/) 34 | bower_components 35 | 36 | # node-waf configuration 37 | .lock-wscript 38 | 39 | # Compiled binary addons (https://nodejs.org/api/addons.html) 40 | build/Release 41 | 42 | # Dependency directories 43 | node_modules/ 44 | jspm_packages/ 45 | 46 | # Snowpack dependency directory (https://snowpack.dev/) 47 | web_modules/ 48 | 49 | # TypeScript cache 50 | *.tsbuildinfo 51 | 52 | # Optional npm cache directory 53 | .npm 54 | 55 | # Optional eslint cache 56 | .eslintcache 57 | 58 | # Microbundle cache 59 | .rpt2_cache/ 60 | .rts2_cache_cjs/ 61 | .rts2_cache_es/ 62 | .rts2_cache_umd/ 63 | 64 | # Optional REPL history 65 | .node_repl_history 66 | 67 | # Output of 'npm pack' 68 | *.tgz 69 | 70 | # Yarn Integrity file 71 | .yarn-integrity 72 | 73 | # dotenv environment variables file 74 | .env 75 | .env.test 76 | .env.production 77 | 78 | # parcel-bundler cache (https://parceljs.org/) 79 | .cache 80 | .parcel-cache 81 | 82 | # Next.js build output 83 | .next 84 | out 85 | 86 | # Nuxt.js build / generate output 87 | .nuxt 88 | dist 89 | 90 | # Gatsby files 91 | .cache/ 92 | # Comment in the public line in if your project uses Gatsby and not Next.js 93 | # https://nextjs.org/blog/next-9-1#public-directory-support 94 | # public 95 | 96 | # vuepress build output 97 | .vuepress/dist 98 | 99 | # Serverless directories 100 | .serverless/ 101 | 102 | # FuseBox cache 103 | .fusebox/ 104 | 105 | # DynamoDB Local files 106 | .dynamodb/ 107 | 108 | # TernJS port file 109 | .tern-port 110 | 111 | # Stores VSCode versions used for testing VSCode extensions 112 | .vscode-test 113 | 114 | # yarn v2 115 | .yarn/cache 116 | .yarn/unplugged 117 | .yarn/build-state.yml 118 | .yarn/install-state.gz 119 | .pnp.* 120 | -------------------------------------------------------------------------------- /contact.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 11 | 14 | 17 | 18 | 19 | 20 | 21 | 37 |
38 |
39 |
40 |
Contact Me
41 |

Email: krithiksuvarna@gmail.com

42 |

phone: 9876543210

43 | Go somewhere 44 |
45 |
46 | 47 |
48 |
49 | 50 |
51 | 52 |
53 | 54 |
55 | 56 |
57 |
58 |
59 | 60 | 61 | 62 | --------------------------------------------------------------------------------