{"id":457,"date":"2015-08-18T02:48:40","date_gmt":"2015-08-18T02:48:40","guid":{"rendered":"http:\/\/shabeebk.com\/blog\/?p=457"},"modified":"2015-09-15T19:10:40","modified_gmt":"2015-09-15T19:10:40","slug":"simple-web-server-using-nodejs","status":"publish","type":"post","link":"http:\/\/shabeebk.com\/blog\/simple-web-server-using-nodejs\/","title":{"rendered":"Simple web server using nodejs"},"content":{"rendered":"<p>We can make a folder just like a web server using nodejs\u00a0for quick jobs<\/p>\n<p>First we can install connect and expressjs, serve-static with Node.js:<\/p>\n<pre class=\"lang:default decode:true\" title=\"npm install\">$ npm install connect serve-static<\/pre>\n<p>We can make .js file (serve.js) and write the below code in that file:<\/p>\n<pre class=\"lang:default decode:true \" title=\"serve-static\">var connect = require('connect');\r\nvar serveStatic = require('serve-static');\r\nconnect().use(serveStatic(__dirname)).listen(8080);<\/pre>\n<p>Then in cmd, run this file:<\/p>\n<pre class=\"lang:default decode:true \">$ node server.js<\/pre>\n<p>Now we can access the local server in URL:<\/p>\n<pre class=\"lang:default decode:true \"> http:\/\/localhost:8080\/myfiles.html<\/pre>\n<p>And can exit by pressing:<\/p>\n<pre class=\"lang:default decode:true \">ctrl+c<\/pre>\n\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"457\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;8,619&nbsp;total views, &nbsp;1&nbsp;views today<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We can make a folder just like a web server using nodejs\u00a0for quick jobs First we can install connect and expressjs, serve-static with Node.js: $ npm install connect serve-static We can make .js file (serve.js) and write the below code in that file: var connect = require(&#8216;connect&#8217;); var serveStatic = require(&#8216;serve-static&#8217;); connect().use(serveStatic(__dirname)).listen(8080); Then in cmd, [&hellip;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"457\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;8,619&nbsp;total views, &nbsp;1&nbsp;views today<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[4,51,1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v18.4.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Simple web server using nodejs<\/title>\n<meta name=\"description\" content=\"Simple web server using nodejs\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/shabeebk.com\/blog\/simple-web-server-using-nodejs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Simple web server using nodejs\" \/>\n<meta property=\"og:description\" content=\"Simple web server using nodejs\" \/>\n<meta property=\"og:url\" content=\"http:\/\/shabeebk.com\/blog\/simple-web-server-using-nodejs\/\" \/>\n<meta property=\"og:site_name\" content=\"shabeeb Blog\" \/>\n<meta property=\"article:published_time\" content=\"2015-08-18T02:48:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-09-15T19:10:40+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"shabeeb\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"http:\/\/shabeebk.com\/blog\/#website\",\"url\":\"http:\/\/shabeebk.com\/blog\/\",\"name\":\"shabeeb Blog\",\"description\":\"A developer blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/shabeebk.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/shabeebk.com\/blog\/simple-web-server-using-nodejs\/#webpage\",\"url\":\"http:\/\/shabeebk.com\/blog\/simple-web-server-using-nodejs\/\",\"name\":\"Simple web server using nodejs\",\"isPartOf\":{\"@id\":\"http:\/\/shabeebk.com\/blog\/#website\"},\"datePublished\":\"2015-08-18T02:48:40+00:00\",\"dateModified\":\"2015-09-15T19:10:40+00:00\",\"author\":{\"@id\":\"http:\/\/shabeebk.com\/blog\/#\/schema\/person\/71832abe654179971635c65c09bceb29\"},\"description\":\"Simple web server using nodejs\",\"breadcrumb\":{\"@id\":\"http:\/\/shabeebk.com\/blog\/simple-web-server-using-nodejs\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/shabeebk.com\/blog\/simple-web-server-using-nodejs\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/shabeebk.com\/blog\/simple-web-server-using-nodejs\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/shabeebk.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Simple web server using nodejs\"}]},{\"@type\":\"Person\",\"@id\":\"http:\/\/shabeebk.com\/blog\/#\/schema\/person\/71832abe654179971635c65c09bceb29\",\"name\":\"shabeeb\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"http:\/\/shabeebk.com\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/0.gravatar.com\/avatar\/9998389cc76a77663881c48f7d4cbba0?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/0.gravatar.com\/avatar\/9998389cc76a77663881c48f7d4cbba0?s=96&d=mm&r=g\",\"caption\":\"shabeeb\"},\"description\":\"Developer,Entrepreneur, software engineer more than that a human being\",\"sameAs\":[\"http:\/\/shabeebk.com\/blog\"],\"url\":\"http:\/\/shabeebk.com\/blog\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Simple web server using nodejs","description":"Simple web server using nodejs","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/shabeebk.com\/blog\/simple-web-server-using-nodejs\/","og_locale":"en_US","og_type":"article","og_title":"Simple web server using nodejs","og_description":"Simple web server using nodejs","og_url":"http:\/\/shabeebk.com\/blog\/simple-web-server-using-nodejs\/","og_site_name":"shabeeb Blog","article_published_time":"2015-08-18T02:48:40+00:00","article_modified_time":"2015-09-15T19:10:40+00:00","twitter_misc":{"Written by":"shabeeb"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"http:\/\/shabeebk.com\/blog\/#website","url":"http:\/\/shabeebk.com\/blog\/","name":"shabeeb Blog","description":"A developer blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/shabeebk.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/shabeebk.com\/blog\/simple-web-server-using-nodejs\/#webpage","url":"http:\/\/shabeebk.com\/blog\/simple-web-server-using-nodejs\/","name":"Simple web server using nodejs","isPartOf":{"@id":"http:\/\/shabeebk.com\/blog\/#website"},"datePublished":"2015-08-18T02:48:40+00:00","dateModified":"2015-09-15T19:10:40+00:00","author":{"@id":"http:\/\/shabeebk.com\/blog\/#\/schema\/person\/71832abe654179971635c65c09bceb29"},"description":"Simple web server using nodejs","breadcrumb":{"@id":"http:\/\/shabeebk.com\/blog\/simple-web-server-using-nodejs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/shabeebk.com\/blog\/simple-web-server-using-nodejs\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/shabeebk.com\/blog\/simple-web-server-using-nodejs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/shabeebk.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Simple web server using nodejs"}]},{"@type":"Person","@id":"http:\/\/shabeebk.com\/blog\/#\/schema\/person\/71832abe654179971635c65c09bceb29","name":"shabeeb","image":{"@type":"ImageObject","@id":"http:\/\/shabeebk.com\/blog\/#personlogo","inLanguage":"en-US","url":"http:\/\/0.gravatar.com\/avatar\/9998389cc76a77663881c48f7d4cbba0?s=96&d=mm&r=g","contentUrl":"http:\/\/0.gravatar.com\/avatar\/9998389cc76a77663881c48f7d4cbba0?s=96&d=mm&r=g","caption":"shabeeb"},"description":"Developer,Entrepreneur, software engineer more than that a human being","sameAs":["http:\/\/shabeebk.com\/blog"],"url":"http:\/\/shabeebk.com\/blog\/author\/admin\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/posts\/457"}],"collection":[{"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/comments?post=457"}],"version-history":[{"count":13,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/posts\/457\/revisions"}],"predecessor-version":[{"id":537,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/posts\/457\/revisions\/537"}],"wp:attachment":[{"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/media?parent=457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/categories?post=457"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/tags?post=457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}