{"id":21330,"date":"2016-04-17T03:01:58","date_gmt":"2016-04-16T17:01:58","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=21330"},"modified":"2016-04-17T12:35:37","modified_gmt":"2016-04-17T02:35:37","slug":"node-js-and-node-local-web-server-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/node-js-and-node-local-web-server-primer-tutorial\/","title":{"rendered":"Node.js and Node Local Web Server Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/NodeJs\/index.html\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"Node.js and Node Local Web Server Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Mac\/NodeJs\/node_js-114of.jpg\" title=\"Node.js and Node Local Web Server Primer Tutorial\"  id='oiis' onmouseover=\" this.src=this.src.replace('-114of.j','-94of.xj').replace('-94of.j','-95of.xj').replace('-95of.j','-96of.xj').replace('-96of.j','-97of.xj').replace('-97of.j','-98of.xj').replace('-98of.j','-99of.xj').replace('-99of.j','-100of.xj').replace('-100of.j','-101of.xj').replace('-101of.j','-102of.xj').replace('-102of.j','-103of.xj').replace('-103of.j','-104of.xj').replace('-104of.j','-105of.xj').replace('-105of.j','-106of.xj').replace('-106of.j','-107of.xj').replace('-107of.j','-108of.xj').replace('-108of.j','-109of.xj').replace('-109of.j','-110of.xj').replace('-110of.j','-111of.xj').replace('-111of.j','-112of.xj').replace('-112of.j','-113of.xj').replace('-113of.j','-114of.xj').replace('.xj','.j'); \" \/><\/a><p class=\"wp-caption-text\">Node.js and Node Local Web Server Primer Tutorial<\/p><\/div>\n<p>We love PHP for web server work, but readily acknowledge &#8230;<\/p>\n<ol>\n<li>PHP is losing out, in popularity terms, to frameworks like <a target=_blank title='Node.js installation download webpage' href='https:\/\/nodejs.org\/en\/download\/'>Node.js<\/a> (which we introduce to you today with a &#8220;Hello World&#8221; tutorial, where you&#8217;ll see its Javascript (yes, Javascript), in (server side) action)<\/li>\n<li>Node.js is a framework that has Javascript running on the server side, a pretty powerful scenario<\/li>\n<\/ol>\n<p> &#8230; and so, a great divide in programming (frameworks) is developing.  Personally, I like the division of &#8220;language&#8221; between PHP server code and Javascript client code, but can see the &#8220;cuteness&#8221; of just thinking &#8220;Javascript&#8221;, and so, today, we show you a Node.js installation on our MacBook Pro using Mac OS X, though you will see, if you take a skeg at our <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/NodeJs\/index.html\" title='Click picture'>slideshow<\/a> that Node.js is very much cross-platform by nature.<\/p>\n<p>If you read this blog, you&#8217;ll (hopefully) have seen how fond we PHP&#8217;ers are here regarding the &#8230;<\/p>\n<p><code><br \/>\n<a target=_blank title='MAMP local web server for Mac OS X' href='https:\/\/www.mamp.info\/'><i>MAMP<\/i><\/a> local web server on port <i>8888<\/i> supporting <i>PHP<\/i> and a <i>MySql<\/i> database on port 8889 on a MacBook Pro Mac OS X using web browsers<br \/>\n<\/code><\/p>\n<p> &#8230; well with Node.js, the scenario is &#8230;<\/p>\n<p><code><br \/>\n<i>Node<\/i> local web server on port <i>3000<\/i> supporting <i>Javascript (Node.js like)<\/i> and a <i>MySql<\/i> database (still) on port 8889 (in our case because we co-exist with MAMP and have MAMP running and access its socket file to make the MySql connection) if co-existing with (running) MAMP or port 3306 (it looks like) if there is no MAMP involved<br \/>\n<\/code><\/p>\n<p>And so, today, we first show a client &#8220;facing&#8221; &#8220;Hello World&#8221; scenario of just showing &#8230; &#8220;Hello World&#8221; &#8230; a web application &#8220;frontend&#8221; if you will.<\/p>\n<p>Then we got a MySql database involved &#8230; a web application &#8220;backend&#8221; if you will &#8230; and we hope if you are a regular reader at this blog &#8230; even though this blog posting <i>may have<\/i> &#8220;rocked your world&#8221; with (Node.js) Javascript getting involved at the server side (though we did warn you with our very first Javascript DOM focused tutorial called <a target=_blank title='JavaScript and the DOM Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-and-the-dom-tutorial\/'>JavaScript and the DOM Tutorial<\/a>?! &#8230; it&#8217;s taken a while for the &#8220;wheel&#8221; to turn!) &#8230; databases always involve server side code, and so we update the <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/NodeJs\/hello_world.js_GETME\" title=\"hello_world.js\">hello_world.js<\/a> to include showing the results of our MySql query &#8230;<\/p>\n<p><code><br \/>\nSELECT * FROM CIRCLE, POINT WHERE pointid=originid<br \/>\n<\/code><\/p>\n<p> &#8230; linked, &#8220;back in the day&#8221; with this <a target=_blank title='MySql Stored Procedures Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/mysql-stored-procedures-primer-tutorial\/'>MySql Stored Procedures Primer Tutorial<\/a> &#8230; and after some dead ends where we didn&#8217;t know whether to have MAMP running or not &#8230; the slideshow is &#8220;warts &#8216;n all&#8221; &#8230; we end up finding out that <i>Node\/Node.js (Javascript)\/MySql<\/i> can co-exist and be an alternative to our cherished <i>MAMP (local Apache web server)\/PHP\/MySql<\/i> &#8220;power triplet&#8221;.  To have a few methods to try things can&#8217;t be that bad &#8230; huh?!  Stay tuned please.<\/p>\n<p>We (almost) leave you with the Open Source links that made the research (culminating in today&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/NodeJs\/node_js-114of.jpg\" title='Tutorial picture'>tutorial picture<\/a>) possible &#8230; thanks &#8230;<\/p>\n<ul>\n<a target=_blank title='Node.js installation download webpage' href='https:\/\/nodejs.org\/en\/download\/'>Node.js installer download webpage &#8230; you download, then for Mac OS X, run package installer<\/a><\/li>\n<p><a target=_blank title='Node.js installation after download and package file install' href='http:\/\/expressjs.com\/en\/starter\/installing.html'>First steps after Node.js download and package installation, about further installation steps at Mac OS X Terminal application&#8217;s command line environment, regarding how to create Node\/Node.js project (directories) and (sub-project-)install steps<\/a><\/li>\n<p><a target=_blank title='MySql connection' href='https:\/\/codeforgeek.com\/2015\/01\/nodejs-mysql-tutorial\/'>Useful regarding (first draft) Node.js connection to MySql example<\/a><\/li>\n<p><a target=_blank title='npm install mysql' href='http:\/\/stackoverflow.com\/questions\/18134411\/cannot-find-module-mysql-node-js'>Useful link leading us to understand that we needed &#8216;npm install mysql&#8217; (via npm package registry) to install MySql module for Node\/Node.js<\/a><\/li>\n<p><a target=_blank title='MySql connection MAMP socket idea' href='http:\/\/stackoverflow.com\/questions\/30266221\/node-js-mysql-error-connect-econnrefused'>Useful regarding Node.js connection to MySql showing how MAMP socket can be used for co-existance<\/a><\/li>\n<p><a target=_blank title='PHP vs Node.js discussion' href='http:\/\/www.infoworld.com\/article\/2866712\/php\/php-vs-node-js-an-epic-battle-for-developer-mind-share.html'>Discussion of PHP vs Node.js<\/a><\/li>\n<\/ul>\n<p>Another player in this realm of thinking is Ruby (on Rails), and with this in mind, take a read of <a target=_blank title='Ruby on Rails Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/ruby-on-rails-primer-tutorial\/'>Ruby on Rails Primer Tutorial<\/a> where port 3000 is used with a local web server arrangement, as well.  Finally, if all this &#8220;web server&#8221; talk interests you as much as us, we&#8217;ve been compiling &#8220;web server&#8221; talk, so to speak into this one <a target=_blank title='Cassini++ WebServer Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/cassini-webserver-primer-tutorial'>Cassini++ WebServer Primer Tutorial<\/a> blog posting, where Node.js thinking from today has been added &#8230; Cassini++ ? &#8230; Cassini is the simplest (Windows) local web server we can think of, and we work discussions up from that.  That tutorial also mentions <a target=_blank title='Mojito Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/mojito-primer-tutorial'>Mojito Primer Tutorial<\/a> which also shows Javascript on both sides of the ledger with Node.js getting involved.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d21201' onclick='var dv=document.getElementById(\"d21201\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/hello-world\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d21201' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We love PHP for web server work, but readily acknowledge &#8230; PHP is losing out, in popularity terms, to frameworks like Node.js (which we introduce to you today with a &#8220;Hello World&#8221; tutorial, where you&#8217;ll see its Javascript (yes, Javascript), &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/node-js-and-node-local-web-server-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,12,29,37],"tags":[125,212,1849,299,468,558,611,652,714,744,827,1859,840,1858,932,938,997,1122,1186,1319,1411],"class_list":["post-21330","post","type-post","status-publish","format-standard","hentry","category-database","category-elearning","category-operating-system","category-tutorials","tag-backend","tag-client","tag-coding","tag-database-2","tag-frontend","tag-hello-world","tag-install","tag-javascript","tag-local-web-server","tag-mamp","tag-mysql","tag-node","tag-node-js","tag-npm","tag-php","tag-phpmyadmin","tag-programming","tag-server","tag-sql","tag-tutorial","tag-web-server"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/21330"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=21330"}],"version-history":[{"count":26,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/21330\/revisions"}],"predecessor-version":[{"id":21366,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/21330\/revisions\/21366"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=21330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=21330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=21330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}