background preloader

NODE.JS

Facebook Twitter

Mastering Node. Node is an exciting new platform developed by Ryan Dahl, allowing JavaScript developers to create extremely high performance servers by leveraging Google's V8 JavaScript engine, and asynchronous I/O.

Mastering Node

In Mastering Node we will discover how to write high concurrency web servers, utilizing the CommonJS module system, node's core libraries, third party modules, high level web development and more. In this chapter we will be looking at the installation and compilation of node. Although there are several ways we may install node, we will be looking at homebrew, nDistro, and the most flexible method, of course - compiling from source.

Homebrew Homebrew is a package management system for OSX written in Ruby, is extremely well adopted, and easy to use. . $ brew install node.js nDistro nDistro is a distribution toolkit for node, which allows creation and installation of node distros within seconds. . $ cd /usr/local/bin && curl | sh $ ndistro Building From Source $ git clone && cd node. Introduction to npm. Static Version This was the third in a series of posts leading up to Node.js Knockout on how to use node.js. npm is a NodeJS package manager.

Introduction to npm

As its name would imply, you can use it to install node programs. Also, if you use it in development, it makes it easier to specify and link dependencies. Installing npm First of all, install NodeJS. To install npm in one command, you can do this: curl | sh Of course, if you're more paranoid than lazy, you can also get the latest code, check it all out, and when you're happy there's nothing in there to pwn your machine, issue a make install or make dev. what, no sudo?

I strongly encourage you not to do package management with sudo! I recommend doing this once instead: sudo chown -R $USER /usr/local That sets your user account as the owner of the /usr/local directory, so that you can just issue normal commands in there. It's much better this way. Getting help: npm help npm has a lot of help documentation about all of its commands. Showing things: npm ls. About this Documentation Node.js v0.8.14 Manual.

The goal of this documentation is to comprehensively explain the Node.js API, both from a reference as well as a conceptual point of view.

About this Documentation Node.js v0.8.14 Manual

Each section describes a built-in module or high-level concept. Where appropriate, property types, method arguments, and the arguments provided to event handlers are detailed in a list underneath the topic heading. Every .html document has a corresponding .json document presenting the same information in a structured manner. This feature is experimental, and added for the benefit of IDEs and other utilities that wish to do programmatic things with the documentation. Every .html and .json file is generated based on the corresponding .markdown file in the doc/api/ folder in node's source tree. Stability Index# Throughout the documentation, you will see indications of a section's stability.

The stability indices are as follows: Stability: 0 - Deprecated This feature is known to be problematic, and changes are planned. JSON Output# Stability: 1 - Experimental. Modules Node.js v0.8.14 Manual. Stability: 5 - Locked Node has a simple module loading system.

Modules Node.js v0.8.14 Manual

In Node, files and modules are in one-to-one correspondence. As an example, foo.js loads the module circle.js in the same directory. The contents of foo.js: var circle = require('. The contents of circle.js: var PI = Math.PI; exports.area = function (r) { return PI * r * r;}; exports.circumference = function (r) { return 2 * PI * r;}; The module circle.js has exported the functions area() and circumference(). Variables local to the module will be private, as though the module was wrapped in a function. If you want the root of your module's export to be a function (such as a constructor) or if you want to export a complete object in one assignment instead of building it one property at a time, assign it to module.exports instead of exports. Below, bar.js makes use of the square module, which exports a constructor: var square = require('.

The square module is defined in square.js: Cycles# Consider this situation: