Node.js Quick-Start on Mac OS X Easy Guide

August 5th, 2013 by Regaz

Quick-Start with Node.js on Mac OS X

The Tutorial Shows You Step-by-Step How-to Quick-Start with Node.js on Mac OS X System.

Node.js is an Amazing New Javascript Stuff that is at the Same Time either a Web Server and a Web Development Framework.

Node.js is Well Known for his Performances and Scaling Attitudes derived from a Single Thread Non-Blocking Architecture “First come, first served”.

The Content and Details are Expressly Reduced to Give Focus Only to the Essentials Instructions and Commands and Make the Guide Easier to Read and Digest ;)

To the How-to Quick-Start with Node.js on Mac OS X Bottom You Find Link to Guide with Extended Documentation for Node.js Javascript Server/Framework.

Quick-Start with Node.js on Mac OS X - Featured

  1. Installing Node.js & npm on Mac OS X

    Mac node.js Getting-Started
  2. Open a Terminal window
  3. Install hotnode Utility
    sudo npm -g install hotnode

    The Tool will Provide to Auto-Reloading the Server when New Changes are Saved.

  4. Editing the Hello-World Node Server
    nano server.js

    Inserts something Like:

    var http = require('http');
    var path = require('path');
    var pages = [
    	{route: '', output: 'Hello World! :)'},
    	{route: 'about', output: 'A simple routing with Node example'},
    	{route: 'another page', output: function() {return 'Here\'s '+this.route;}},
    ];
    
    http.createServer(function (request, response) {
    	var lookup = path.basename(decodeURI(request.url));
    	pages.forEach(function(page) {
    		if (page.route === lookup) {
    			response.writeHead(200, {'Content-Type': 'text/html'});
    			response.end(typeof page.output === 'function' ? page.output() : page.output);
    		}
    	});
    	if (!response.finished) {
    		response.writeHead(404);
    		response.end('Page Not Found!');
    	}
    }).listen(8080);
    
  5. Start the Server/App
    node server.js

    Next you can Display the Hello-World on:

    http://127.0.0.1:8080/

  6. Node.js Manual & Documentation

    Node.js Docs
  7. Now You are Able to Getting-Started with the Node.js Development, to Look for Further Docs and Resource meet the Online Node.js Developers Community.

(Visited 3 times, 1 visits today)

Tags: , , , , , , , , , , , , ,


Comments are disabled