Hello world in node.js
By Anatoly Mironov
I know, node.js has been present for a while. But I actually had no time to try it. I was surprised that now it is very straight forward to start with node.js. Allright, everything begins with Hello world. Eventhough it is available for allmost all combinations of operating systems and servers, the easiest way to test it was actually Ubuntu. To install just run:
sudo apt-get install nodejs
```Then make a new directory and create the hello.js:
mkdir hello cd hello vi hello.js
[![](https://sharepointkunskap.files.wordpress.com/2012/03/helloworld-nodejs-002.png "helloworld-nodejs-002")](https://sharepointkunskap.files.wordpress.com/2012/03/helloworld-nodejs-002.png) The javascript code creates a server, instructs what to send back as a response and says to node to listen to port 40113 (what a weird number :) )
var http = require(‘http’); http.createServer(function(req, res) { res.writeHead(200, {‘Content-Type’: ’text/plain; charset=utf-8’ }); res.end(‘Salam tĕnce!’); }).listen(40113);
node hello.js
##### node.js on c9.io (Cloud9 IDE)
Even simpler way to try node.js is to create an app in Cloud9 IDE. [Begin with a hello-world app](http://support.cloud9ide.com/entries/20640198-lesson-3-writing-a-node-js-hello-world-program). [![](https://sharepointkunskap.files.wordpress.com/2012/03/an-vaska.png "an-vaska")](https://sharepointkunskap.files.wordpress.com/2012/03/an-vaska.png) That's it.
##### Now some other useful links for starting with node.js:
* [Building a web server in node.js. Introduction by Marc Qualie](http://blog.marcqualie.com/2011/11/introduction-to-nodejs-building-web.html)
* [Cloning Twitter in node.js in a few hours: live blogging of Travis Glines.](http://www.travisglines.com/web-coding/lets-make-a-twitter-clone-in-node-js)
* [Heroku, node.js and mongodb: amazing combination. See such a web app example in the Embedded Fun blog](http://embeddedfun.blogspot.com/2011/11/heroku-nodejs-mongolab.html).
* [node.js and IIS... and the best ASP.NET IAAS provider appharbor. See an example of publishing a chat in node.js and mongodb on appharbor.](http://blog.appharbor.com/2012/01/19/announcing-node-js-support)
* [Build your node.js app in c9.io and deploy it to azure](http://weblogs.asp.net/shijuvarghese/archive/2012/03/08/building-and-deploying-node-js-apps-to-windows-azure-using-cloud9-ide.aspx)
* [Create a node.js app with github, cloud9 and heroku](http://charless.org/?p=283)
Update: [If you want to get the latest node package, you shouldn't install nodejs from apt](http://srirangan.net/2011-09-setup-node-js-and-npm-on-ubuntu). Just clone the node git repo, compile and update the PATH. npm package is preinstalled then:
git clone git:github.com/joyent/node.git cd node ./configure make sudo make install export PATH=${PATH}:/usr/local/bin
sudo apt-get install python-software-properties sudo add-apt-repository ppa:chris-lea/node.js sudo apt-get update sudo apt-get install nodejs npm
##### node.js and SharePoint
[Luc Stakenborg](http://allthatjs.com/2012/03/29/node-js-meet-sharepoint) has developed [a node.js package for retrieving data from SharePoint](http://search.npmjs.org/#/sharepoint). To use it, install two packages:
npm install xml2js npm install sharepoint
var SP = require(‘sharepoint’), site = ‘http://yourdomain.sharepoint.com/teamsite', username = ‘yourusername’, password = ‘yourpassword’;
var client = new SP.RestService(site), posts = client.list(‘Posts’);
var showResponse = function (err, data) { console.log(data); }
client.signin(username, password, function () { posts.get(showResponse) });
[![](https://sharepointkunskap.files.wordpress.com/2012/03/node-sp.png "node-sp")](https://sharepointkunskap.files.wordpress.com/2012/03/node-sp.png)
##### javascript console in Powershell
It can't be easier. If node is installed, just fire up PowerShell and type node: [![](https://sharepointkunskap.files.wordpress.com/2012/03/nodejs-powershell.png "nodejs-powershell")](https://sharepointkunskap.files.wordpress.com/2012/03/nodejs-powershell.png)
## Comments from Wordpress.com
####
[Hello.js | Fix Runtime Errors & BSOD's](http://www.fixruntimeerror.net/hello-js.php "") - <time datetime="2014-09-04 19:10:18">Sep 4, 2014</time>
\[…\] Hello world in node.js – CHUVASH.eu | CHunky Universe of … – Then make a new directory and create the hello.js: mkdir hello cd hello vi hello.js. The javascript code creates a server, … Powered by WordPress.com %d bloggers like this: … \[…\]
<hr />