CHUVASH.eu

CHunky Universe of Vigourous Astonishing SHarepoint :)

Hello world in node.js

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

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);

After that, just start the node process:

node hello.js

Very simple. Now go to localhost:40113 and see the result!

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.

That’s it.

Now some other useful links for starting with node.js:

Update:

If you want to get the latest node package, you shouldn’t install nodejs from apt. 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

Or add a new repository to get the latest stable version of node.js

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 has developed a node.js package for retrieving data from SharePoint. To use it, install two packages:

npm install xml2js
npm install sharepoint

Then create a js file with this content:

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)
});

javascript console in Powershell

It can’t be easier. If node is installed, just fire up PowerShell and type node:

Advertisements

One response to “Hello world in node.js

  1. Pingback: Hello.js | Fix Runtime Errors & BSOD's

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Discovering SharePoint

And having fun doing it

Bram de Jager talking Office 365, SharePoint and Azure

My view and thoughts on Productivity and more.

My programming life

and everything in between

SharePoint Development Lab by @avishnyakov

It is a good place to share some SharePoint stories and development practices.

SharePoint Dragons

Nikander & Margriet on SharePoint

RealActivity - Real-time and trustworthy

Blog site of founder, RealActivty - Paul J. Swider

Mai Omar Desouki - Avid SharePointer

Egyptian & Vodafoner - Senior SharePoint Consultant

Cameron Dwyer | Office 365, SharePoint, Outlook, OnePlace Solutions

Office 365, SharePoint, OnePlace Solutions & Life's Other Little Wonders

paul.tavares

Me and My doings!

Share SharePoint Points!!

By Mohit Vashishtha

Jimmy Janlén "Den Scrummande Konsulten"

Erfarenheter, synpunkter och raljerande om Scrum från Jimmy Janlén

SPJoel

SharePoint for everyone

SharePointRyan

Ryan Dennis is a SharePoint Solution Architect with a passion for SharePoint and PowerShell

SharePoint 2020

The Vision for a Future of Clarity

Aharoni in Unicode, ya mama

Treacle tarts for great justice

... And All That JS

JavaScript, Web Apps and SharePoint

blksthl

Mostly what I know about SharePoint - CommunicoCuspis

%d bloggers like this: