{"id":8765,"date":"2023-10-11T08:41:00","date_gmt":"2023-10-11T08:41:00","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=8765"},"modified":"2023-10-11T08:41:00","modified_gmt":"2023-10-11T08:41:00","slug":"read-a-file-in-nodejs","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/node\/read-a-file-in-nodejs","title":{"rendered":"Read a File in Node.js"},"content":{"rendered":"<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var http = require('http');\r\nvar fs = require('fs');\r\nvar server = http.createServer(function (req, resp) {\r\n    fs.readFile(\"AppPages\/MyPage.html\", function (error, pgResp) {\r\n        if (error) {\r\n            resp.writeHead(404);\r\n            resp.write('Contents you are looking are Not Found');\r\n        } else {\r\n            resp.writeHead(200, { 'Content-Type': 'text\/html' });\r\n            resp.write(pgResp);\r\n        }\r\n        resp.end();\r\n    });\r\n});\r\nserver.listen(5050);\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>var http = require(&#8216;http&#8217;); var fs = require(&#8216;fs&#8217;); var server = http.createServer(function (req, resp) { fs.readFile(&#8220;AppPages\/MyPage.html&#8221;, function (error, pgResp) { if (error) { resp.writeHead(404); resp.write(&#8216;Contents you are looking are Not Found&#8217;); } else { resp.writeHead(200, { &#8216;Content-Type&#8217;: &#8216;text\/html&#8217; }); resp.write(pgResp); } resp.end(); }); }); server.listen(5050);<\/p>\n","protected":false},"author":1,"featured_media":8766,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[8],"tags":[],"class_list":["post-8765","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-node"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/8765"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=8765"}],"version-history":[{"count":2,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/8765\/revisions"}],"predecessor-version":[{"id":8768,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/8765\/revisions\/8768"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/8766"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=8765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=8765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=8765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}