NodeJS in 5 minutes

Download Mac Installer
http://nodejs.org

Install and note that node was installed at

/usr/local/bin/node

npm (Node Package Manager)  was installed at
/usr/local/bin/npm

Make sure that /usr/local/bin is in your $PATH.

echo $PATH

Use npm to install node.js packages. This will install package XYZ in current directory

npm install XYZ

This will install package XYZ globally

npm install -g XYZ

Install driver/mapping for MongoDB

npm install mongoose

install rest library

npm install restify

Put your .js files in a Site directory and run them:

node myserver.js

Here is an example from the Node site

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

save this file in your Sites directory as example.js and run the node server

node example.js

Now open the path to the server in a browser

http://127.0.0.1:1337/

Advertisements

Leave a comment

No comments yet.

Comments RSS TrackBack Identifier URI

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