{"id":62,"date":"2017-10-02T20:15:58","date_gmt":"2017-10-02T20:15:58","guid":{"rendered":"http:\/\/wpdev.ecko.me\/?p=62"},"modified":"2017-10-02T20:15:58","modified_gmt":"2017-10-02T20:15:58","slug":"simple-http-server-in-nodejs","status":"publish","type":"post","link":"https:\/\/crownandluxury.com\/?p=62","title":{"rendered":"Getting Started with NodeJS: Simple HTTP Server"},"content":{"rendered":"\n<p>Node.js uses an event-driven, non-blocking model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. This simple web server written in <a href=\"https:\/\/nodejs.org\/en\/about\/\" target=\"_blank\">Node<\/a> responds with \u201cHello World\u201d for every request. To run the server, put the code into a file example.js and execute it with the node program from the command line.<\/p>\n\n\n\n<!--more-->\n\n\n\n<pre class=\"wp-block-code eckosc_syntax eckosc_syntax_theme_dark wp-block-code__dark language-javascript\" data-language=\"language-javascript\" data-color-scheme=\"dark\"><code>var http = require('http');\nhttp.createServer(function (req, res) {\n    res.writeHead(200, {'Content-Type': 'text\/plain'});\n    res.end('Hello Worldn');\n}).listen(1337, '127.0.0.1');\nconsole.log('Server running at http:\/\/127.0.0.1:1337\/');<\/code><\/pre>\n\n\n\n<p>This is in contrast to today&#8217;s more common concurrency model where OS threads are employed. Thread-based networking is relatively inefficient and very difficult to use. Furthermore, users of Node are free from worries of dead-locking the process\u2014there are no locks. Almost no function in Node directly performs I\/O, so the process never blocks. Because nothing blocks, less-than-expert programmers are able to develop scalable systems.<\/p>\n\n\n\n<p>Just because Node is designed without threads, doesn&#8217;t mean you cannot take advantage of multiple cores in your environment. You can spawn child processes that are easy to communicate with by using our <code>child_process.fork()<\/code> API. Built upon that same interface is the cluster module, which allows you to share sockets between processes to enable load balancing over your cores.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Node.js is a platform built on Chrome\u2019s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.<\/p>\n","protected":false},"author":1,"featured_media":959,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"link","meta":{"footnotes":""},"categories":[4],"tags":[13,31],"class_list":["post-62","post","type-post","status-publish","format-link","has-post-thumbnail","hentry","category-javascript","tag-development","tag-web","post_format-post-format-link"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Getting Started with NodeJS: Simple HTTP Server - Crown an Luxury Timepieces<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/crownandluxury.com\/?p=62\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Getting Started with NodeJS: Simple HTTP Server - Crown an Luxury Timepieces\" \/>\n<meta property=\"og:description\" content=\"Node.js is a platform built on Chrome\u2019s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/crownandluxury.com\/?p=62\" \/>\n<meta property=\"og:site_name\" content=\"Crown an Luxury Timepieces\" \/>\n<meta property=\"article:published_time\" content=\"2017-10-02T20:15:58+00:00\" \/>\n<meta name=\"author\" content=\"CrownAndLuxury\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"CrownAndLuxury\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/crownandluxury.com\/?p=62\",\"url\":\"https:\/\/crownandluxury.com\/?p=62\",\"name\":\"Getting Started with NodeJS: Simple HTTP Server - Crown an Luxury Timepieces\",\"isPartOf\":{\"@id\":\"https:\/\/crownandluxury.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/crownandluxury.com\/?p=62#primaryimage\"},\"image\":{\"@id\":\"https:\/\/crownandluxury.com\/?p=62#primaryimage\"},\"thumbnailUrl\":\"https:\/\/crownandluxury.com\/wp-content\/uploads\/2016\/02\/image-1.jpg\",\"datePublished\":\"2017-10-02T20:15:58+00:00\",\"author\":{\"@id\":\"https:\/\/crownandluxury.com\/#\/schema\/person\/689dd98bb396b64007dc7139deb62482\"},\"breadcrumb\":{\"@id\":\"https:\/\/crownandluxury.com\/?p=62#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/crownandluxury.com\/?p=62\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/crownandluxury.com\/?p=62#primaryimage\",\"url\":\"https:\/\/crownandluxury.com\/wp-content\/uploads\/2016\/02\/image-1.jpg\",\"contentUrl\":\"https:\/\/crownandluxury.com\/wp-content\/uploads\/2016\/02\/image-1.jpg\",\"width\":1920,\"height\":1200},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/crownandluxury.com\/?p=62#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/crownandluxury.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Getting Started with NodeJS: Simple HTTP Server\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/crownandluxury.com\/#website\",\"url\":\"https:\/\/crownandluxury.com\/\",\"name\":\"Crown an Luxury Timepieces\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/crownandluxury.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/crownandluxury.com\/#\/schema\/person\/689dd98bb396b64007dc7139deb62482\",\"name\":\"CrownAndLuxury\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/crownandluxury.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1eef7995d66a0a390150f32f123dda9c52df4bb23af2e403d2f9d5ea8babaa82?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1eef7995d66a0a390150f32f123dda9c52df4bb23af2e403d2f9d5ea8babaa82?s=96&d=mm&r=g\",\"caption\":\"CrownAndLuxury\"},\"sameAs\":[\"https:\/\/crownandluxury.com\"],\"url\":\"https:\/\/crownandluxury.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Getting Started with NodeJS: Simple HTTP Server - Crown an Luxury Timepieces","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":"https:\/\/crownandluxury.com\/?p=62","og_locale":"en_US","og_type":"article","og_title":"Getting Started with NodeJS: Simple HTTP Server - Crown an Luxury Timepieces","og_description":"Node.js is a platform built on Chrome\u2019s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.","og_url":"https:\/\/crownandluxury.com\/?p=62","og_site_name":"Crown an Luxury Timepieces","article_published_time":"2017-10-02T20:15:58+00:00","author":"CrownAndLuxury","twitter_card":"summary_large_image","twitter_misc":{"Written by":"CrownAndLuxury","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/crownandluxury.com\/?p=62","url":"https:\/\/crownandluxury.com\/?p=62","name":"Getting Started with NodeJS: Simple HTTP Server - Crown an Luxury Timepieces","isPartOf":{"@id":"https:\/\/crownandluxury.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/crownandluxury.com\/?p=62#primaryimage"},"image":{"@id":"https:\/\/crownandluxury.com\/?p=62#primaryimage"},"thumbnailUrl":"https:\/\/crownandluxury.com\/wp-content\/uploads\/2016\/02\/image-1.jpg","datePublished":"2017-10-02T20:15:58+00:00","author":{"@id":"https:\/\/crownandluxury.com\/#\/schema\/person\/689dd98bb396b64007dc7139deb62482"},"breadcrumb":{"@id":"https:\/\/crownandluxury.com\/?p=62#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/crownandluxury.com\/?p=62"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/crownandluxury.com\/?p=62#primaryimage","url":"https:\/\/crownandluxury.com\/wp-content\/uploads\/2016\/02\/image-1.jpg","contentUrl":"https:\/\/crownandluxury.com\/wp-content\/uploads\/2016\/02\/image-1.jpg","width":1920,"height":1200},{"@type":"BreadcrumbList","@id":"https:\/\/crownandluxury.com\/?p=62#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/crownandluxury.com\/"},{"@type":"ListItem","position":2,"name":"Getting Started with NodeJS: Simple HTTP Server"}]},{"@type":"WebSite","@id":"https:\/\/crownandluxury.com\/#website","url":"https:\/\/crownandluxury.com\/","name":"Crown an Luxury Timepieces","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/crownandluxury.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/crownandluxury.com\/#\/schema\/person\/689dd98bb396b64007dc7139deb62482","name":"CrownAndLuxury","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/crownandluxury.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/1eef7995d66a0a390150f32f123dda9c52df4bb23af2e403d2f9d5ea8babaa82?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1eef7995d66a0a390150f32f123dda9c52df4bb23af2e403d2f9d5ea8babaa82?s=96&d=mm&r=g","caption":"CrownAndLuxury"},"sameAs":["https:\/\/crownandluxury.com"],"url":"https:\/\/crownandluxury.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/crownandluxury.com\/index.php?rest_route=\/wp\/v2\/posts\/62","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/crownandluxury.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/crownandluxury.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/crownandluxury.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/crownandluxury.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=62"}],"version-history":[{"count":0,"href":"https:\/\/crownandluxury.com\/index.php?rest_route=\/wp\/v2\/posts\/62\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/crownandluxury.com\/index.php?rest_route=\/wp\/v2\/media\/959"}],"wp:attachment":[{"href":"https:\/\/crownandluxury.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=62"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/crownandluxury.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=62"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/crownandluxury.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=62"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}