<!doctypehtml><html lang=en xml:lang=en xmlns=http://www.w3.org/1999/xhtml><meta content="text/html; charset=utf-8"http-equiv=Content-Type><meta content=upgrade-insecure-requests http-equiv=Content-Security-Policy><meta content=width=device-width,user-scalable=yes,initial-scale=0.5,minimum-scale=0.5,maximum-scale=1 name=viewport><link href=favicon.png rel=icon type=image/png><title>
   The Node Beginner Book - A comprehensive Node.js tutorial
  </title><meta content="A comprehensive Node.js tutorial for beginners: Learn how to build a full blown web application with server-side JavaScript"name=description><meta content="The Node Beginner Book"property=og:site_name><meta content=en_US property=og:locale><meta content=book property=og:type><meta content=1144782312 property=fb:profile_id><meta content=150404395523663 property=fb:app_id><meta content=https://www.facebook.com/NodeBeginner/ property=book:author><meta content=9781471628443 property=book:isbn><meta content=Node.js property=book:tag><meta content=JavaScript property=book:tag><meta content=Programming property=book:tag><meta content=Software property=book:tag><meta content=Tutorial property=book:tag><meta content=319963981788483 property=fb:pages><meta content=https://www.nodebeginner.org property=og:url><meta content="The Node Beginner Book"property=og:title><meta content=https://www.nodebeginner.org/nodebeginner_org-opengraph-image.png property=og:image><meta content=https://www.nodebeginner.org/nodebeginner_org-opengraph-image.png property=og:image:secure_url><meta content=1200 property=og:image:width><meta content=630 property=og:image:height><meta content="A comprehensive and elegant introduction to the world of Node.js software development for absolute beginners."property=og:description><style>body {
            font-family: 'Georgia', serif;
            background-color: #eee;
            padding-top: 0px;
        }

        h2, h3, h4, h5, h6 {
            font-family: 'Open Sans', sans-serif;
        }

        #outermost {
            width: 860px;
            margin: 0 auto;
        }

        #forkmeongithub img {
            z-index: 5;
            position: absolute;
            top: 0;
            right: 0;
            border: 0;
        }

        #book, #disqus_thread, #footer {
            margin: 0 auto;
            margin-top: 24px;
            margin-bottom: 100px;
            padding: 64px;
            background-color: white;
            border-top: 1px solid #ddd;
            border-left: 1px solid #ddd;
            border-bottom: 1px solid #ddd;
            border-right: 1px solid #ddd;
            z-index: 100;
            box-shadow: 14px 11px 27px #888;
        }

        #book {
            margin-top: 94px;
        }

        #author {
            margin-top: -46px;
            margin-left: 279px;
            color: #888;
            font-family: 'Open Sans', sans-serif;
            font-size: 100%;
            font-style: normal;
        }

        #workinprogressnote p {
            font-family: 'Open Sans', sans-serif;
            color: #700;
            text-align: center;
        }

        #buybox, #buybox-inner, #translations {
            font-family: 'Open Sans', sans-serif;
            font-size: 13px;
            color: #fff;
            text-align: center;
            padding: 8px;
            padding-left: 32px;
            padding-right: 32px;
            border-radius: 8px;
            box-shadow: 0px 0px 4px #444;
            position: relative;
            margin-bottom: 20px;
            margin-left: auto;
            margin-right: auto;
            width: 100%;
            background-color: #555;
        }

        #sitenav {
            background-color: #fff;
            text-align: center;
            margin-top: 32px;
            margin-bottom: 16px;
            padding: 16px;
        }

        #sitenav-inner {
            margin: 0 auto;
            font-family: 'Open Sans', sans-serif;
            font-size: 13px;
        }

        #sitenav-inner a {
            text-decoration: none;
        }

        #sitenav-inner a:hover {
            text-decoration: underline;
        }

        #translations {
            max-width: 640px;
        }

        #translations table {
            margin: 0 auto;
        }

        #translations img {
            border: none;
        }

        #translations td {
            text-align: left;
            vertical-align: top;
        }

        #translations a {
            text-decoration: none;
            color: #fff;
        }

        #translations .flag {
            margin-top: 20px;
            vertical-align: middle;
            padding-top: 4px;
        }
        #translations .text {
            display: inline-block;
            vertical-align: middle;
            margin-right: 24px;
        }

        #buybox {
            background: none;
            border: none;
            box-shadow: none;
            padding: 0;
        }

        #buybox-inner {
            padding-bottom: 20px;
            display: block;
            margin: 0 auto;
            max-width: 640px;
        }

        #buybox-inner.cn {
            float: none;
            padding-bottom: 20px;
            display: block;
            margin: 0 auto;
        }

        #buybox-inner .cover {
            width: 170px;
            display: table-cell;
            padding-right: 0px;
            padding-left: 16px;
            vertical-align: top;
            align: center;
            color: #bbb;
        }

        #buybox-inner .cover img {
            border: 1px solid black;
            box-shadow: 0 1px 2px rgba(0,0,0,0.4), inset -1px 1px 0 rgba(255,255,255,0.4);
            -moz-box-shadow: 0 1px 2px rgba(0,0,0,0.4), inset -1px 1px 0 rgba(255,255,255,0.4);
            -webkit-box-shadow: 0 1px 2px rgba(0,0,0,0.4), inset -1px 1px 0 rgba(255,255,255,0.4);
        }

        #buybox-inner .description {
            width: 260px;
            display: table-cell;
            padding-right: 16px;
            padding-left: 16px;
            vertical-align: top;
            text-align: center;
        }

        #buybox-inner strong.price {
            font-size: 18pt;
            color: #14d014;
        }

        #buybox-inner strong.price.dollarsign {
            font-weight: normal;
        }

        .price sup {
            font-size: 10pt;
            font-weight: normal;
        }

        #buybox-inner .buy {
            display: table-cell;
            vertical-align: top;
            color: #bbb;
        }

        #buybox-inner .button, #salespitch .button {
            padding: 8px;
            margin-top: 26px;
            margin-left: auto;
            margin-right: auto;
            width: 140px;
            border: 1px solid #444;
            border-radius: 6px;
            background-image: -moz-linear-gradient(top, #14d014, #029302);
            background-image: -webkit-gradient(linear, center top, center bottom, from(#14d014), to(#029302));
            box-shadow: 0 1px 2px rgba(0,0,0,0.4), inset -1px 1px 0 rgba(255,255,255,0.4);
            -moz-box-shadow: 0 1px 2px rgba(0,0,0,0.4), inset -1px 1px 0 rgba(255,255,255,0.4);
            -webkit-box-shadow: 0 1px 2px rgba(0,0,0,0.4), inset -1px 1px 0 rgba(255,255,255,0.4);
            text-align: center;
            font-family: 'Open Sans', sans-serif;
        }

        .buttonlink {
            text-decoration: none;
            font-weight: bold;
            font-size: 15px;
            color: #fff;
            text-shadow: 0.1em 0.1em #666;
        }

        #donate p {
            font-family: 'Open Sans', sans-serif;
            text-align: center;
        }

        #paypal fieldset {
            border: 0;
        }

        #disqus_thread {
            font-family: 'Open Sans', sans-serif;
        }

        #footer {
            font-family: 'Open Sans', sans-serif;
            background-color: #f5f5f5;
            margin-top: 100px;
        }

        #footer p {
            text-align: center;
            font-family: 'Open Sans', sans-serif;
            font-size: 11px;
        }

        #ccimage {
            float: left;
            margin-left: 30px;
            margin-right: 0;
            margin-top: 20px;
        }

        #praise {
            position: absolute;
            top: 120px;
            right: 40px;
            width: 204px;
            font-style: italic;
            color: #aaa;
            z-index: -1;
            text-align: right;
        }

        #praise .praise {
            margin-bottom: 25px;
        }

        #praise .author {
            font-style: normal;
            font-size: 75%;
        }

        #table-of-contents-headline {
            margin-top: 48px;
            color: #700;
            font-size: 160%;
            font-weight: bold;
        }

        #book #table-of-contents {
            margin-left: -24px;
            font-family: 'Open Sans', sans-serif;
        }

        #book #table-of-contents ul li {
            font-size: 100%;
            margin-left: 0;
            list-style-type: none;
        }

        #book #table-of-contents ul {
            padding-left: 24px;
            margin-top: 12px;
            margin-left: 0;
            margin-bottom: 36px;
        }

        h1 {
            margin-left: -63px;
            margin-top: -109px;
            font-size: 300%;
            color: #700;
            font-style: italic;
            font-weight: bold;
        }

        h2 {
            margin-top: 64px;
            font-size: 180%;
        }

        h3 {
            font-size: 160%;
        }

        h4 {
            font-size: 140%;
        }

        h5 {
            font-size: 120%;
        }

        h3, h4, h5 {
            margin-top: 36px;
        }

        h2, h3, h4, h5 {
            color: #700;
            font-weight: bold;
            margin-bottom: 36px;
        }

        #salespitch {
            font-family: 'Open Sans', sans-serif;
            width: 90%;
            max-width: 640px;
            margin: 0 auto;
        }

        #salespitch .bundle-book {
            overflow: hidden;
        }

        #salespitch .bundle-book-image {
            width: 100px;
            float: left;
        }

        #salespitch .bundle-book-image img {
            box-shadow: 2px 2px 1px #bbb;
        }

        #salespitch .bundle-book-text {
            overflow: hidden;
        }

        #salespitch .bundle-book-connection {
            text-align: center;
            font-size: 36pt;
            font-weight: bolder;
            color: #6b6;
            margin-top: -16px;
            margin-bottom: 8px;
        }

        #authorimage {
            float: right;
            padding-left: 32px;
            padding-bottom: 4px;
        }

        #salespitch .box {
            text-align: center;
            width: 200px;
            background-color: #eee;
            border-radius: 16px;
            padding: 32px;
            margin: 0 auto;
        }

        #salespitch .box .subinfo {
            font-size: 10pt;
            color: #777;
        }

        #salespitch .box .subinfo strong {
            font-size: 14pt;
            color: #080;
        }

        #bubble {
            border: 1px solid #999;
            border-radius: 16px;
            padding: 32px;
            background-color: #ffe;
            margin-bottom: 60px;
        }

        #salespitch .orbox {
            width: 200px;
            margin: 0 auto;
            text-align: center;
            padding: 24px;
        }

        #hiddenhalf {
            opacity: 0.075;
        }

        #book p {
            text-align: justify;
            font-size: 110%;
            line-height: 150%;
            margin-bottom: 48px;
            margin-top: -22px;
        }

        pre {
            font-family: 'Source Code Pro', Menlo, Monaco, Courier, monospace;
            background-color: #f7f7f7;
            border: 1px solid #eee;
            padding: 16px;
            margin-bottom: 64px;
            margin-top: -24px;
            font-size: 14px;
            white-space: pre-wrap;       /* Since CSS 2.1 */
            white-space: -moz-pre-wrap;  /* Mozilla, since 1999 */
            white-space: -pre-wrap;      /* Opera 4-6 */
            white-space: -o-pre-wrap;    /* Opera 7 */
            word-wrap: break-word;       /* Internet Explorer 5.5+ */
        }

        pre.prettyprint {
            background-color: #f7f7f7;
            border: 1px solid #eee;
            padding: 16px;
            margin-bottom: 64px;
            margin-top: -24px;
            font-size: 14px;
        }

        #book div ul {
            margin-top: -24px;
            margin-bottom: 48px;
        }

        #salespitch div ul {
            margin-top: 22px;
        }

        #book div ul li {
            margin-bottom: 12px;
            font-size: 110%;
        }

        blockquote {
            font-style: italic;
        }

        /* Prettify */
        .str {
            color: #080
        }

        .kwd {
            color: #008
        }

        .com {
            color: #800
        }

        .typ {
            color: #606
        }

        .lit {
            color: #066
        }

        .pun {
            color: #660
        }

        .pln {
            color: #000
        }

        .tag {
            color: #008
        }

        .atn {
            color: #606
        }

        .atv {
            color: #080
        }

        .dec {
            color: #606
        }

        ol.linenums {
            margin-top: 0;
            margin-bottom: 0
        }

        li.L0, li.L1, li.L2, li.L3, li.L5, li.L6, li.L7, li.L8 {
            list-style: none
        }

        li.L1, li.L3, li.L5, li.L7, li.L9 {
            background: #eee
        }

        .sales-testimonials-box {
            background-color: white;
            padding: 32px;
            overflow: hidden;
            margin: -32px;
            margin-top: 32px;
            border-radius: 16px;
        }

        .sales-testimonial {
            clear: both;
        }

        .sales-testimonial div.text {
            background-color: #fbfbfb;
            color: #202020;
            border: 1px solid #eee;
            border-radius: 16px;
            padding: 28px 44px 28px 64px;
            font-size: 18px;
        }

        .sales-testimonial span.quotationmark-start {
            display: inline-block;
            font-size: 98px;
            color: #dfdfdf;
            line-height: 0;
            padding-top: 28px;
            float: left;
            position: absolute;
            font-family: "Georgia", "Times New Roman", serif;
            margin-left: -44px;
        }

        .sales-testimonial span.quotationmark-end {
            display: inline-block;
            font-size: 98px;
            color: #dfdfdf;
            line-height: 0;
            padding-top: 45px;
            float: left;
            position: absolute;
            font-family: "Georgia", "Times New Roman", serif;
            padding-left: 6px;
        }

        .sales-testimonial div.image {
            display: inline-block;
            float: left;
            padding-top: 11px;
            padding-left: 3px;
            margin-bottom: 48px;
        }

        .sales-testimonial div.image.right {
            float: right;
        }

        .sales-testimonial div.author {
            display: inline-block;
            float: left;
            margin-top: 14px;
            margin-left: 16px;
            margin-right: 16px;
            font-size: 20px;
            font-weight: bold;
            color: #0084B4;
        }

        .sales-testimonial span.source {
            font-weight: normal;
            color: #777;
        }

        .sales-testimonial div.author.right {
            float: right;
        }

        @media only print {
            #book {
                margin-top: 60px;
            }

            #book, #footer {
                border: none;
                box-shadow: none;
            }

            #footer {
                border-top: 1px solid black;
            }

            #translations {
                display: none;
            }

            #buybox-inner {
                display: none;
            }

            #disqus_thread {
                display: none;
            }

            #forkmeongithub {
                display: none;
            }
            #praise {
                display: none;
            }
        }

        @media only screen and (max-width: 1440px) {
            #praise {
                display: none;
            }
        }

        @media only screen and (max-width: 960px) {
            #praise {
                display: none;
            }

            #outermost {
                max-width: 720px;
            }

            #buybox, #buybox-inner, #translations {
                font-size: 17px;
            }

            #sitenav-inner a {
                display: block;
                font-size: 18px;
                margin-bottom: 4px;
            }

            #footer p {
                font-size: 18px;
            }
        }</style><link href=https://www.nodebeginner.org/ rel=canonical><link href=/ hreflang=en rel=alternate><link href=/index-jp.html hreflang=ja rel=alternate><link href=/index-es.html hreflang=es rel=alternate><link href=/index-br.html hreflang=es-BR rel=alternate><link href=/index-kr.html hreflang=ko rel=alternate><link href=/index-vi.html hreflang=vi rel=alternate><link href=/index-zh-cn.html hreflang=zh-cn rel=alternate><link href=/index-zh-tw.html hreflang=zh-tw rel=alternate><link href=http://msud.ir/nbpersian/online/ hreflang=fa rel=alternate><link href=http://www.nodebeginner.ru hreflang=ru rel=alternate><script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
        m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-2127388-6', 'auto');
    ga('send', 'pageview');</script><script type=application/ld+json>
   {
          "@context": "http://schema.org",
          "@type": "Book",
          "name": "The Node Beginner Book",
          "author": {
            "@type": "Person",
            "name": "Manuel Kiessling"
          },
          "url": "https://www.nodebeginner.org",
          "sameAs": "https://www.nodebeginner.org",
          "workExample":
          [
            {
              "@type": "Book",
              "isbn": "9781471628443",
              "bookFormat": "http://schema.org/EBook",
              "potentialAction": {
                "@type": "ReadAction",
                "target": {
                  "@type": "EntryPoint",
                  "urlTemplate": "https://leanpub.com/b/node-beginner-and-craftsman-bundle",
                  "actionPlatform": [
                    "http://schema.org/DesktopWebPlatform",
                    "http://schema.org/MobileWebPlatform",
                    "http://schema.org/IOSPlatform",
                    "http://schema.org/AndroidPlatform"
                  ]
                },
                "expectsAcceptanceOf": {
                  "@type": "Offer",
                  "Price": 9.00,
                  "priceCurrency": "USD",
                  "availability": "http://schema.org/InStock"
                }
              }
            }
          ]
        }
  </script><body><div id=outermost><aside id=buybox><div id=buybox-inner><div class=cover><p>The perfect introduction plus its comprehensive follow-up now in one bundle!</p><a class="salelink vwo-conv-link-bundle-2-top"href=https://leanpub.com/b/node-beginner-and-craftsman-bundle> <img height=86 src=the_node_beginner_book_cover_small.png width=57> </a><a class="salelink vwo-conv-link-bundle-2-top"href=https://leanpub.com/b/node-beginner-and-craftsman-bundle> <img height=86 src=the_node_craftsman_book_cover_small.png width=57> </a></div><div class=description><p>Leanpub.com currently offers <br> the final version of <br> <strong> The Node Beginner Book </strong> <br> plus its follow-up <br> <strong> The Node Craftsman Book </strong> <br> <br> for <strong class="price dollarsign"> $ </strong> <strong class=price> 9 </strong> only! <br> <br> (limited offer - regular price is $29.99)</div><div class=buy><p>224 pages in total <br> PDF, ePub & MOBI <br> Free lifetime updates <br> <br> Unconditional 45 days <br> money back guarantee</p><a class="buttonlink salelink vwo-conv-link-bundle-2-top"href=https://leanpub.com/b/node-beginner-and-craftsman-bundle> <div class=button>Buy this <br> bundle now</div> </a></div></div></aside><nav id=sitenav><div id=sitenav-inner><p><a href=blog/> More Node.js tutorials: <strong> The Node Beginner Blog </strong> </a><p><a href=web-development-beginner-tutorial/> New guide: <strong> Software development for the web from the ground up </strong> </a><p><a href=http://beginning-mobile-app-development-with-react-native.com/> New eBook: <strong> Write mobile apps using React Native </strong> </a></div></nav><div id=book><article><h1>The Node Beginner Book</h1><address id=author>A Node.js tutorial by <a href=https://twitter.com/manuelkiessling rel=author> Manuel Kiessling </a></address><section><a name=about> </a><h2>About</h2><p>The aim of this document is to get you started with developing applications with Node.js, teaching you everything you need to know about "advanced" JavaScript along the way. It goes way beyond your typical "Hello World" tutorial.</section><section><a name=status> </a><h3>Status</h3><p>You are reading the final version of this book, i.e., updates are only done to correct errors or to reflect changes in new versions of Node.js. It was last updated on June 5, 2017.<p>The code samples in this book are tested to work with both the Long Term Support version 6.10.3 as well as the most current 8.0.0 version of Node.js.<p>This site allows you to read the first 19 pages of this book for free. The complete text is available as a DRM-free eBook (PDF, ePub and Kindle format). More info is available <a href=#salespitch> at the end of the free part </a> .</section><section><a name=intended-audience> </a><h3>Intended audience</h3><p>This document will probably fit best for readers that have a background similar to my own: experienced with at least one object-oriented language like Ruby, Python, PHP or Java, only little experience with JavaScript, and completely new to Node.js.<p>Aiming at developers that already have experience with other programming languages means that this document won't cover really basic stuff like data types, variables, control structures and the likes. You already need to know about these to understand this document.<p>However, because functions and objects in JavaScript are different from their counterparts in most other languages, these will be explained in more detail.</section><section><a name=structure> </a><h3>Structure of this document</h3><p>Upon finishing this document, you will have created a complete web application which allows the users of this application to view web pages and upload files.<p>Which, of course, is not exactly world-changing, but we will go some extra miles and not only create the code that is "just enough" to make these use cases possible, but create a simple, yet complete framework to cleanly separate the different aspects of our application. You will see what I mean in a minute.<p>We will start with looking at how JavaScript development in Node.js is different from JavaScript development in a browser.<p>Next, we will stay with the good old tradition of writing a "Hello World" application, which is a most basic Node.js application that "does" something.<p>Then, we will discuss what kind of "real" application we want to build, dissect the different parts which need to be implemented to assemble this application, and start working on each of these parts step-by-step.<p>As promised, along the way we will learn about some of the more advanced concepts of JavaScript, how to make use of them, and look at why it makes sense to use these concepts instead of those we know from other programming languages.<p>The source code of the finished application is available through <a href=https://github.com/ManuelKiessling/NodeBeginnerBook/tree/master/code/application> the NodeBeginnerBook Github repository </a> .</section><section><h3>Table of contents</h3><div id=table-of-contents><ul><li><a href=#about> About </a> <ul><li><a href=#status> Status </a><li><a href=#intended-audience> Intended audience </a><li><a href=#structure> Structure of this document </a></ul><li><a href=#javascript-and-nodejs> JavaScript and Node.js </a> <ul><li><a href=#javascript-and-you> JavaScript and You </a><li><a href=#a-word-of-warning> A word of warning </a><li><a href=#server-side-javascript> Server-side JavaScript </a><li><a href=#hello-world> "Hello World" </a></ul><li><a href=#a-full-blown-web-application-with-nodejs> A full blown web application with Node.js </a> <ul><li><a href=#the-use-cases> The use cases </a><li><a href=#the-application-stack> The application stack </a></ul><li><a href=#building-the-application-stack> Building the application stack </a> <ul><li><a href=#a-basic-http-server> A basic HTTP server </a><li><a href=#analyzing-our-http-server> Analyzing our HTTP server </a><li><a href=#passing-functions-around> Passing functions around </a><li><a href=#how-function-passing-makes-our-http-server-work> How function passing makes our HTTP server work </a><li><br> <strong> Chapters available in the <a href=https://leanpub.com/b/node-beginner-and-craftsman-bundle> full book </a> : </strong> <br> <br><li>Event-driven asynchronous callbacks<li>How our server handles requests<li>Finding a place for our server module<li>What's needed to "route" requests?<li>Execution in the kingdom of verbs<li>Routing to real request handlers<li>Making the request handlers respond <ul><li>How to not do it<li>Blocking and non-blocking<li>Responding request handlers with non-blocking operation</ul><li>Serving something useful <ul><li>Handling POST requests<li>Handling file uploads</ul><li>Conclusion and outlook</ul></ul></div></section><section><a name=javascript-and-nodejs> </a><h2>JavaScript and Node.js</h2><a name=javascript-and-you> </a><h3>JavaScript and You</h3><p>Before we talk about all the technical stuff, let's take a moment and talk about you and your relationship with JavaScript. This chapter is here to allow you to estimate if reading this document any further makes sense for you.<p>If you are like me, you started with HTML "development" long ago, by writing HTML documents. You came across this funny thing called JavaScript, but you only used it in a very basic way, adding interactivity to your web pages every now and then.<p>What you really wanted was "the real thing", you wanted to know how to build complex web sites - you learned a programming language like PHP, Ruby, Java, and started writing "backend" code.<p>Nevertheless, you kept an eye on JavaScript, you saw that with the introduction of jQuery, Prototype and the likes, things got more advanced in JavaScript land, and that this language really was about more than <em> window.open() </em> .<p>However, this was all still frontend stuff, and although it was nice to have jQuery at your disposal whenever you felt like spicing up a web page, at the end of the day you were, at best, a JavaScript <em> user </em> , but not a JavaScript <em> developer </em> .<p>And then came Node.js. JavaScript on the server, how cool is that?<p>You decided that it's about time to check out the old, new JavaScript. But wait, writing Node.js applications is one thing; understanding why they need to be written the way they are written means - understanding JavaScript. And this time for real.<p>Here is the problem: Because JavaScript really lives two, maybe even three lives (the funny little DHTML helper from the mid-90's, the more serious frontend stuff like jQuery and the likes, and now server-side), it's not that easy to find information that helps you to learn JavaScript the "right" way, in order to write Node.js applications in a fashion that makes you feel you are not just using JavaScript, you are actually developing it.<p>Because that's the catch: you already are an experienced developer, you don't want to learn a new technique by just hacking around and mis-using it; you want to be sure that you are approaching it from the right angle.<p>There is, of course, excellent documentation out there. But documentation alone sometimes isn't enough. What is needed is guidance.<p>My goal is to provide a guide for you.</p><a name=a-word-of-warning> </a><h3>A word of warning</h3><p>There are some really excellent JavaScript people out there. I'm not one of them.<p>I'm really just the guy I talked about in the previous paragraph. I know a thing or two about developing backend web applications, but I'm still new to "real" JavaScript and still new to Node.js. I learned some of the more advanced aspects of JavaScript just recently. I'm not experienced.<p>Which is why this is no "from novice to expert" book. It's more like "from novice to advanced novice".<p>If I don't fail, then this will be the kind of document I wish I had when starting with Node.js.</p><a name=server-side-javascript> </a><h3>Server-side JavaScript</h3><p>The first incarnations of JavaScript lived in browsers. But this is just the context. It defines what you can do with the language, but it doesn't say much about what the language itself can do. JavaScript is a "complete" language: you can use it in many contexts and achieve everything with it you can achieve with any other "complete" language.<p>Node.js really is just another context: it allows you to run JavaScript code in the backend, outside a browser.<p>In order to execute the JavaScript you intend to run in the backend, it needs to be interpreted and, well, executed. This is what Node.js does, by making use of Google's V8 VM, the same runtime environment for JavaScript that Google Chrome uses.<p>Plus, Node.js ships with a lot of useful modules, so you don't have to write everything from scratch, like for example something that outputs a string on the console.<p>Thus, Node.js is really two things: a runtime environment and a library.<p>In order to make use of these, you need to install Node.js. Instead of repeating the process here, I kindly ask you to visit <a title="Building and Installing Node.js"href=https://nodejs.org/en/download/> the official installation page </a> . Please come back once you are up and running.</p><a name=hello-world> </a><h3>"Hello World"</h3><p>Ok, let's just jump in the cold water and write our first Node.js application: "Hello World".<p>Open your favorite editor and create a file called <em> helloworld.js </em> . We want it to write "Hello World" to STDOUT, and here is the code needed to do that:<pre class="prettyprint lang-js"><span class=pln>console</span><span class=pun>.</span><span class=pln>log</span><span class=pun>(</span><span class=str>"Hello World"</span><span class=pun>);</span></pre><p>Save the file, and execute it through Node.js:<pre>node helloworld.js</pre><p>This should output <em> Hello World </em> on your terminal.<p>Ok, this stuff is boring, right? Let's write some real stuff.</section><section><a name=a-full-blown-web-application-with-nodejs> </a><h2>A full blown web application with Node.js</h2><section><a name=the-use-cases> </a><h3>The use cases</h3><p>Let's keep it simple, but realistic:<div><ul><li>The user should be able to use our application with a web browser<li>The user should see a welcome page when requesting http:// <em> domain </em> /start which displays a file upload form<li>By choosing an image file to upload and submitting the form, this image should then be uploaded to http:// <em> domain </em> /upload, where it is displayed once the upload is finished</ul></div><p>Fair enough. Now, you could achieve this goal by googling and hacking together <em> something </em> . But that's not what we want to do here.<p>Furthermore, we don't want to write only the most basic code to achieve the goal, however elegant and correct this code might be. We will intentionally add more abstraction than necessary in order to get a feeling for building more complex Node.js applications.</section><section><a name=the-application-stack> </a><h3>The application stack</h3><p>Let's dissect our application. Which parts need to be implemented in order to fulfill the use cases?<div><ul><li>We want to serve web pages, therefore we need an <strong> HTTP server </strong><li>Our server will need to answer differently to requests, depending on which URL the request was asking for, thus we need some kind of <strong> router </strong> in order to map requests to request handlers<li>To fulfill the requests that arrived at the server and have been routed using the router, we need actual <strong> request handlers </strong><li>The router probably should also treat any incoming POST data and give it to the request handlers in a convenient form, thus we need <strong> request data handling </strong><li>We not only want to handle requests for URLs, we also want to display content when these URLs are requested, which means we need some kind of <strong> view logic </strong> the request handlers can use in order to send content to the user's browser<li>Last but not least, the user will be able to upload images, so we are going to need some kind of <strong> upload handling </strong> which takes care of the details</ul></div><p>Let's think a moment about how we would build this stack with PHP. It's not exactly a secret that the typical setup would be an Apache HTTP server with mod_php installed. <br> Which in turn means that the whole "we need to be able to serve web pages and receive HTTP requests" stuff doesn't happen within PHP itself.<p>Well, with node, things are a bit different. Because with Node.js, we not only implement our application, we also implement the whole HTTP server. In fact, our web application and its web server are basically the same.<p>This might sound like a lot of work, but we will see in a moment that with Node.js, it's not.<p>Let's just start at the beginning and implement the first part of our stack, the HTTP server.</section></section><section><a name=building-the-application-stack> </a><h2>Building the application stack</h2><section><a name=a-basic-http-server> </a><h3>A basic HTTP server</h3><p>When I arrived at the point where I wanted to start with my first "real" Node.js application, I wondered not only how to actually code it, but also how to organize my code. <br> Do I need to have everything in one file? Most tutorials on the web that teach you how to write a basic HTTP server in Node.js have all the logic in one place. What if I want to make sure that my code stays readable the more stuff I implement?<p>Turns out, it's relatively easy to keep the different concerns of your code separated, by putting them in modules.<p>This allows you to have a clean main file, which you execute with Node.js, and clean modules that can be used by the main file and among each other.<p>So, let's create a main file which we use to start our application, and a module file where our HTTP server code lives.<p>My impression is that it's more or less a standard to name your main file <em> index.js </em> . It makes sense to put our server module into a file named <em> server.js </em> .<p>Let's start with the server module. Create the file <em> server.js </em> in the root directory of your project, and fill it with the following code:<pre class="prettyprint lang-js"><span class=kwd>var</span><span class=pln> http </span><span class=pun>=</span><span class=pln> require</span><span class=pun>(</span><span class=str>"http"</span><span class=pun>);</span><span class=pln><br><br>http</span><span class=pun>.</span><span class=pln>createServer</span><span class=pun>(</span><span class=kwd>function</span><span class=pun>(</span><span class=pln>request</span><span class=pun>,</span><span class=pln> response</span><span class=pun>)</span><span class=pln> </span><span class=pun>{</span><span class=pln><br>  response</span><span class=pun>.</span><span class=pln>writeHead</span><span class=pun>(</span><span class=lit>200</span><span class=pun>,</span><span class=pln> </span><span class=pun>{</span><span class=str>"Content-Type"</span><span class=pun>:</span><span class=pln> </span><span class=str>"text/plain"</span><span class=pun>});</span><span class=pln><br>  response</span><span class=pun>.</span><span class=pln>write</span><span class=pun>(</span><span class=str>"Hello World"</span><span class=pun>);</span><span class=pln><br>  response</span><span class=pun>.</span><span class=pln>end</span><span class=pun>();</span><span class=pln><br></span><span class=pun>}).</span><span class=pln>listen</span><span class=pun>(</span><span class=lit>8888</span><span class=pun>);</span></pre><p>That's it! You just wrote a working HTTP server. Let's prove it by running and testing it. First, execute your script with Node.js:<pre>node server.js</pre><p>Now, open your browser and point it at <a href=http://localhost:8888/ rel=nofollow> http://localhost:8888/ </a> . This should display a web page that says "Hello World".<p>That's quite interesting, isn't it. How about talking about what's going on here and leaving the question of how to organize our project for later? I promise we'll get back to it.</section><section><a name=analyzing-our-http-server> </a><h3>Analyzing our HTTP server</h3><p>Well, then, let's analyze what's actually going on here.<p>The first line <em> require </em> s the <em> http </em> module that ships with Node.js and makes it accessible through the variable <em> http </em> .<p>We then call one of the functions the http module offers: <em> createServer </em> . This function returns an object, and this object has a method named <em> listen </em> , and takes a numeric value which indicates the port number our HTTP server is going to listen on.<p>Please ignore for a second the function definition that follows the opening bracket of <em> http.createServer </em> .<p>We could have written the code that starts our server and makes it listen at port 8888 like this:<pre class="prettyprint lang-js"><span class=kwd>var</span><span class=pln> http </span><span class=pun>=</span><span class=pln> require</span><span class=pun>(</span><span class=str>"http"</span><span class=pun>);</span><span class=pln><br><br></span><span class=kwd>var</span><span class=pln> server </span><span class=pun>=</span><span class=pln> http</span><span class=pun>.</span><span class=pln>createServer</span><span class=pun>();</span><span class=pln><br>server</span><span class=pun>.</span><span class=pln>listen</span><span class=pun>(</span><span class=lit>8888</span><span class=pun>);</span></pre><p>That would start an HTTP server listening at port 8888 and doing nothing else (not even answering any incoming requests).<p>The really interesting (and, if your background is a more conservative language like PHP, odd looking) part is the function definition right there where you would expect the first parameter of the <em> createServer() </em> call.<p>Turns out, this function definition IS the first (and only) parameter we are giving to the <em> createServer() </em> call. Because in JavaScript, functions can be passed around like any other value.</section><section><a name=passing-functions-around> </a><h3>Passing functions around</h3><p>You can, for example, do something like this:<pre class="prettyprint lang-js"><span class=kwd>function</span><span class=pln> say</span><span class=pun>(</span><span class=pln>word</span><span class=pun>)</span><span class=pln> </span><span class=pun>{</span><span class=pln><br>  console</span><span class=pun>.</span><span class=pln>log</span><span class=pun>(</span><span class=pln>word</span><span class=pun>);</span><span class=pln><br></span><span class=pun>}</span><span class=pln><br><br></span><span class=kwd>function</span><span class=pln> execute</span><span class=pun>(</span><span class=pln>someFunction</span><span class=pun>,</span><span class=pln> value</span><span class=pun>)</span><span class=pln> </span><span class=pun>{</span><span class=pln><br>  someFunction</span><span class=pun>(</span><span class=pln>value</span><span class=pun>);</span><span class=pln><br></span><span class=pun>}</span><span class=pln><br><br>execute</span><span class=pun>(</span><span class=pln>say</span><span class=pun>,</span><span class=pln> </span><span class=str>"Hello"</span><span class=pun>);</span></pre><p>Read this carefully! We pass the function <em> say </em> as the first parameter to the <em> execute </em> function. Not the return value of <em> say </em> , but <em> say </em> itself!<p>Thus, <em> say </em> becomes the local variable <em> someFunction </em> within <em> execute </em> , and execute can call the function in this variable by issuing <em> someFunction() </em> (adding brackets).<p>Of course, because <em> say </em> takes one parameter, <em> execute </em> can pass such a parameter when calling <em> someFunction </em> .<p>We can, as we just did, pass a function as a parameter to another function by its name. But we don't have to take this indirection of first defining, then passing it - we can define and pass a function as a parameter to another function in-place:<pre class="prettyprint lang-js"><span class=kwd>function</span><span class=pln> execute</span><span class=pun>(</span><span class=pln>someFunction</span><span class=pun>,</span><span class=pln> value</span><span class=pun>)</span><span class=pln> </span><span class=pun>{</span><span class=pln><br>  someFunction</span><span class=pun>(</span><span class=pln>value</span><span class=pun>);</span><span class=pln><br></span><span class=pun>}</span><span class=pln><br><br>execute</span><span class=pun>(</span><span class=kwd>function</span><span class=pun>(</span><span class=pln>word</span><span class=pun>){</span><span class=pln> console</span><span class=pun>.</span><span class=pln>log</span><span class=pun>(</span><span class=pln>word</span><span class=pun>)</span><span class=pln> </span><span class=pun>},</span><span class=pln> </span><span class=str>"Hello"</span><span class=pun>);</span></pre><p>We define the function we want to pass to <em> execute </em> right there at the place where <em> execute </em> expects its first parameter.<p>This way, we don't even need to give the function a name, which is why this is called an <em> anonymous function </em> .<p>This is a first glimpse at what I like to call "advanced" JavaScript, but let's take it step by step. For now, let's just accept that in JavaScript, we can pass a function as a parameter when calling another function. We can do this by assigning our function to a variable, which we then pass, or by defining the function to pass in-place.</section><section><a name=how-function-passing-makes-our-http-server-work> </a><h3>How function passing makes our HTTP server work</h3><p>With this knowledge, let's get back to our minimalistic HTTP server:<pre class="prettyprint lang-js"><span class=kwd>var</span><span class=pln> http </span><span class=pun>=</span><span class=pln> require</span><span class=pun>(</span><span class=str>"http"</span><span class=pun>);</span><span class=pln><br><br>http</span><span class=pun>.</span><span class=pln>createServer</span><span class=pun>(</span><span class=kwd>function</span><span class=pun>(</span><span class=pln>request</span><span class=pun>,</span><span class=pln> response</span><span class=pun>)</span><span class=pln> </span><span class=pun>{</span><span class=pln><br>  response</span><span class=pun>.</span><span class=pln>writeHead</span><span class=pun>(</span><span class=lit>200</span><span class=pun>,</span><span class=pln> </span><span class=pun>{</span><span class=str>"Content-Type"</span><span class=pun>:</span><span class=pln> </span><span class=str>"text/plain"</span><span class=pun>});</span><span class=pln><br>  response</span><span class=pun>.</span><span class=pln>write</span><span class=pun>(</span><span class=str>"Hello World"</span><span class=pun>);</span><span class=pln><br>  response</span><span class=pun>.</span><span class=pln>end</span><span class=pun>();</span><span class=pln><br></span><span class=pun>}).</span><span class=pln>listen</span><span class=pun>(</span><span class=lit>8888</span><span class=pun>);</span></pre><p>By now it should be clear what we are actually doing here: we pass the <em> createServer </em> function an anonymous function.<p>We could achieve the same by refactoring our code to:<pre class="prettyprint lang-js"><span class=kwd>var</span><span class=pln> http </span><span class=pun>=</span><span class=pln> require</span><span class=pun>(</span><span class=str>"http"</span><span class=pun>);</span><span class=pln><br><br></span><span class=kwd>function</span><span class=pln> onRequest</span><span class=pun>(</span><span class=pln>request</span><span class=pun>,</span><span class=pln> response</span><span class=pun>)</span><span class=pln> </span><span class=pun>{</span><span class=pln><br>  response</span><span class=pun>.</span><span class=pln>writeHead</span><span class=pun>(</span><span class=lit>200</span><span class=pun>,</span><span class=pln> </span><span class=pun>{</span><span class=str>"Content-Type"</span><span class=pun>:</span><span class=pln> </span><span class=str>"text/plain"</span><span class=pun>});</span><span class=pln><br>  response</span><span class=pun>.</span><span class=pln>write</span><span class=pun>(</span><span class=str>"Hello World"</span><span class=pun>);</span><span class=pln><br>  response</span><span class=pun>.</span><span class=pln>end</span><span class=pun>();</span><span class=pln><br></span><span class=pun>}</span><span class=pln><br><br>http</span><span class=pun>.</span><span class=pln>createServer</span><span class=pun>(</span><span class=pln>onRequest</span><span class=pun>).</span><span class=pln>listen</span><span class=pun>(</span><span class=lit>8888</span><span class=pun>);</span></pre><p>Maybe now is a good moment to ask: Why are we doing it that way?</section><section><a name=event-driven-callbacks> </a><h3>Event-driven asynchronous callbacks</h3><a name=continuereading> </a><p>To understand why Node.js applications have to be written this way, we need to understand how Node.js executes our code. Node's approach isn't unique, but the underlying execution model is different from runtime environments like Python, Ruby, PHP or Java.</section></section></article><a name=salespitch> </a><aside id=salespitch><div id=bubble><img height=160 id=authorimage src=manuelkiessling.jpg width=160><p><br> Hi there! <span id=freeab-text-block> Sorry to interrupt you </span> .<p>My name is Manuel Kiessling, I'm the author of this book.<p>If you have read that far, I would like you to consider buying the eBook version of this book. It's a beautifully crafted package including a PDF, an ePub, and a MOBI file, which means you can read it on all kinds of eReaders out there like the Amazon Kindle, the iPad, or the Sony Reader, and of course on any PC or Mac.<p>But the best thing is that you can buy it bundled together with another great Node.js book at a very attractive discounted price:<div class=bundle-book><div class=bundle-book-image><img height=86 src=the_node_beginner_book_cover_small.png width=57></div><div class=bundle-book-text>The full version of <em> The Node Beginner Book </em> , giving you access to all 54 pages of this tutorial, where I talk about blocking and non-blocking operations, handling POST requests and file uploads, and how to finalize the example application into a working whole.</div></div><div class=bundle-book-connection>+</div><div class=bundle-book><div class=bundle-book-image><img height=86 src=the_node_craftsman_book_cover_small.png width=57></div><div class=bundle-book-text><em> The Node Craftsman Book </em> is the offical follow up to The Node Beginner Book. On 170 pages, it covers the following topics: <ul><li>Working with NPM and Packages<li>Object-oriented JavaScript<li>Test-Driven Node.js Development<li>Synchronous and Asynchronous operations explained<li>Using and creating Event Emitters<li>Node.js and MySQL<li>Node.js and MongoDB<li>Writing fast and efficient code<li>Writing a REST webservice application<li>Combining Node.js and AngularJS<li>Setting up a continuous deployment workflow</ul></div></div><p>Both books together would cost a total of $29.99, but for a limited time, we are offering them as a bundle for only <strong> $9 </strong> . You can download them immediately, they are completely DRM-free, and you will receive any future updates to both books for free.<div class=box><a class="buttonlink salelink vwo-conv-link-bundle-2-bottom"href=https://leanpub.com/b/node-beginner-and-craftsman-bundle> <div class=button>Buy this <br> bundle now</div> </a><p></p><a class="salelink vwo-conv-link-bundle-2-bottom"href=https://leanpub.com/b/node-beginner-and-craftsman-bundle> <img height=86 src=the_node_beginner_book_cover_small.png width=57> </a><a class="salelink vwo-conv-link-bundle-2-bottom"href=https://leanpub.com/b/node-beginner-and-craftsman-bundle> <img height=86 src=the_node_craftsman_book_cover_small.png width=57> </a><br><div class=subinfo>224 pages in total <br> 100% DRM-free <br> Free lifetime updates <br> PDF, Kindle, ePub <br><strong> Only $9 </strong></div></div><div style="margin-top: 40px;"><p><strong> Friendly reminder: </strong> This week only, between November 6 and November 13, both books are also part of <strong> The Ultimate Programmer Super Stack </strong> .<p>The Super Stack gives you direct access to more than 25+ best-in-class ecourses, bestselling books, tools, and bonus resources designed by some of the world's leading programmers, at over 90% off (that's not a typo!).<p>Only this week, you get all the ecourses, books and tools that are part of the Super Stack for <strong> $47.95 </strong> instead of <del> $1,367.88 </del> .<p><strong> <a href=superstack/> Click here to check out The Ultimate Programmer Super Stack. </a> </strong></div><aside class=sales-testimonials-box><div class=sales-testimonial><div class="text left"><span class=quotationmark-start> “ </span> The object-oriented chapter of #nodecraftsman by @manuelkiessling makes OOP #JavaScript click more than any other explanation I've read. <span class=quotationmark-end> ” </span></div><div class="image right"><img height=50 src=testimonial_nickstrayer.jpg width=50></div><div class="author right">Nick Strayer <span class=source> <br> via Twitter </span></div></div><div class=sales-testimonial><div class="text left"><span class=quotationmark-start> “ </span> Thanks to @manuelkiessling for writing the #nodebeginner and #nodecraftsman books. Great intros to a new language for this PHP dev. <span class=quotationmark-end> ” </span></div><div class="image left"><img height=50 src=testimonial_erorus.png width=50></div><div class="author left">Erorus <span class=source> <br> via Twitter </span></div></div><div class=sales-testimonial><div class="text left"><span class=quotationmark-start> “ </span> "Test-Driven development with Node.js", best chapter in the history of chapters! <span class=quotationmark-end> ” </span></div><div class="image right"><img height=50 src=testimonial_benjamintodts.jpg width=50></div><div class="author right">Benjamin Todts <span class=source> <br> via Twitter </span></div></div><div class=sales-testimonial><div class="text left"><span class=quotationmark-start> “ </span> Just starting to read the #nodecraftsman book to learn about node.js! I read #nodebeginner by the same author yesterday, and it was awesome! <span class=quotationmark-end> ” </span></div><div class="image left"><img height=50 src=testimonial_heidinewton.jpg width=50></div><div class="author left">Heidi Newton <span class=source> <br> via eMail </span></div></div></aside></div><br clear=all></aside></div><aside id=praise><div class=praise><div class=comment>"This is an amazing introduction to Node."</div><div class=author>Ryan Dahl, creator of Node.js</div></div><div class=praise><div class=comment>"I love nodebeginner.org - concise, direct to the point and even enjoyable to read."</div><div class=author>Gojko Adzic, author of <em> Specification by Example </em> and <em> Bridging the Communication Gap </em></div></div><div class=praise><div class=comment>"This is one of the best tutorials I've read. As a former Java coder, I've always found JavaScript to be a black art, but you have really simplified things with this tutorial."</div><div class=author>Erskine, from the comments</div></div><div class=praise><div class=comment>"This is one of the few beginner articles I made it all the way through because of how well it's written."</div><div class=author>Paul Gibler, from the comments</div></div><div class=praise><div class=comment>"Indispensable."</div><div class=author>@lecolibrilibre, on Twitter</div></div><div class=praise><div class=comment>"I just wanted to drop you a note to say thank you for writing such an excellent introduction to node. Your book's explanation is fantastic!"</div><div class=author>Seth McLaughlin, via eMail</div></div></aside><aside id=disqus_thread></aside><aside id=translations><table><tbody><tr><td><a href=index-jp.html> <div class=flag><img alt="japanese flag"height=24 src=jp-flag.png width=24></div> <div class=text lang=ja>日本語で読む</div> </a><td><a href=index-es.html> <div class=flag><img alt="spanish flag"height=24 src=es-flag.png width=24></div> <div class=text lang=es>Lee este tutorial en Español</div> </a><td><a href=index-br.html> <div class=flag><img alt="brazilian flag"height=24 src=br-flag.png width=24></div> <div class=text lang=br>Leia esse livro em português</div> </a><td><a href=index-kr.html> <div class=flag><img alt="korean flag"height=24 src=kr-flag.png width=24></div> <div class=text lang=kr>이 튜토리얼을 한글로 보세요</div> </a><tr><td><a href=index-zh-cn.html> <div class=flag><img alt="chinese flag"height=24 src=cn-flag.png width=24></div> <div class=text lang=zh-cn>阅读本书中文版</div> </a><td><a href=index-zh-tw.html> <div class=flag><img alt="chinese flag"height=24 src=cn-flag.png width=24></div> <div class=text lang=zh-tw>阅读本书繁体中文版</div> </a><td><a href=http://www.nodebeginner.ru> <div class=flag><img alt="russian flag"height=24 src=ru-flag.png width=24></div> <div class=text lang=ru>Читать этот учебник на русском</div> </a><td><a href=index-vi.html> <div class=flag><img alt="vietnamese flag"height=24 src=vi-flag.png width=24></div> <div class=text lang=vi>Đọc bằng tiếng Việt</div> </a><td> <td> <tr><td><a href=http://msud.ir/nbpersian/> <div class=flag><img alt="iranian flag"height=24 src=ir-flag.png width=24></div> <div class=text lang=fa style=direction:rtl>به فارسی بخوانید (رایگان)</div> </a><td> <td> <td> </table></aside><div id=footer><p>Copyright 2011-2018 Manuel Kiessling <br> The contents on this website are free for personal use. <br> It is not permitted to copy (with the exception of Github forks), distribute, display, and perform the work, as well as make and distribute derivative works based on it, unless specifically granted.<p><a href=imprint.html> Imprint / Impressum / Datenschutz / Haftung </a></div><script async>var disqus_config = function () {
            this.page.url = 'https://www.nodebeginner.org/';
            this.page.identifier = 'nodebeginner-book';
        };
        (function() { // DON'T EDIT BELOW THIS LINE
            var d = document, s = d.createElement('script');
            s.src = 'https://nodebeginner.disqus.com/embed.js';
            s.setAttribute('data-timestamp', +new Date());
            (d.head || d.body).appendChild(s);
        })();

        // CSS browser select
        function css_browser_selector(u){var ua=u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1},g='gecko',w='webkit',s='safari',o='opera',m='mobile',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3.6')?g+' ff3 ff3_6':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('blackberry')?m+' blackberry':is('android')?m+' android':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?m+' j2me':is('iphone')?m+' iphone':is('ipod')?m+' ipod':is('ipad')?m+' ipad':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win'+(is('windows nt 6.0')?' vista':''):is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js'];c=b.join(' ');h.className+=' '+c;return c;};css_browser_selector(navigator.userAgent);</script></div><style>@import url('https://fonts.googleapis.com/css?family=Open+Sans&subset=latin-ext');</style>