{"id":1752,"date":"2011-11-03T20:44:12","date_gmt":"2011-11-03T20:44:12","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=1752"},"modified":"2011-11-03T21:02:30","modified_gmt":"2011-11-03T21:02:30","slug":"node-install-and-test","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2011\/11\/03\/node-install-and-test\/","title":{"rendered":"Node &#8211; install and test"},"content":{"rendered":"<p>One of my friends asked me what is Node and also how do you install and test to make sure it is working.<\/p>\n<p>Well, <a href=\"http:\/\/nodejs.org\/\" title=\"Node\" target=\"_blank\">Node<\/a> is in essence a javascript server side environment that allows you to write code that will allow the event model to handle requests very quickly since it does not handle the I\/O (well almost of all of the functions within node do not!) so there is no-blocking of code.<\/p>\n<p>Node has a very quick and capable http class that allows for the user to create a server that is capable of doing some very quick responses to multiple connections.  <\/p>\n<p>To install Node you just need to do this in ubuntu <\/p>\n<pre lang=\"bash\">\r\nsudo -s\r\napt-get install python-software-properties\r\nadd-apt-repository ppa:chris-lea\/node.js\r\napt-get update\r\napt-get install nodejs\r\nexit\r\n<\/pre>\n<p>the first line allows you to be the root and thus the next commands are as the user root.<\/p>\n<p>Or if you are using windows just download the executable from <a href=\"http:\/\/nodejs.org\/#download\">here<\/a><\/p>\n<p>To test the node to make sure it is working with a basic &#8220;Hello world!&#8221; example if you save this below as helloworld.js.<\/p>\n<pre lang=\"javascript\">\r\nvar http = require(\"http\");\r\n\/\/ create the http server function req'uest, res'ult\r\nhttp.createServer(function (req, res) \r\n{\r\n    \/\/ 200 = means http response code of found page, then a array of the content type\r\n    res.writeHead(200, {'Content-Type' : 'text\/plain'});\r\n    res.end('Hello world!');  \/\/ write out the text\r\n}).listen(8080,'127.0.0.1');\r\n\/\/ listen on port 8080 on the ip address 127.0.0.1\r\nconsole.log('We have started, check your browser on http:\/\/127.0.0.1:8080\/');\r\n<\/pre>\n<p>I am using a higher number than 1024 for the port because below that you need to be a root user or administrator on windows to allow anything to connect to those port numbers.  <\/p>\n<p>So if you now run the program with the javascript file above as the second parameter<\/p>\n<pre lang=\"bash\">\r\nnode helloworld.js\r\n<\/pre>\n<p>and then if you open your browser at 127.0.0.1:8080  then you will see <\/p>\n<p>Hello world!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of my friends asked me what is Node and also how do you install and test to make sure it is working. Well, Node is in essence a javascript server side environment that allows you to write code that will allow the event model to handle requests very quickly since it does not handle &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2011\/11\/03\/node-install-and-test\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Node &#8211; install and test<\/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":[37,38],"tags":[385],"class_list":["post-1752","post","type-post","status-publish","format-standard","hentry","category-linux_install_configure","category-windows_install_configure","tag-node"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1752","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=1752"}],"version-history":[{"count":4,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1752\/revisions"}],"predecessor-version":[{"id":1756,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1752\/revisions\/1756"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=1752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=1752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=1752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}