background preloader

Learning NodeJS

Facebook Twitter

Ressources. Introduction to Node.js with Ryan Dahl. Asynchronous Code Design with Node.js. Google Cloud Live 2014 – A Humbling Experience Life as a software engineer very rarely exposes you to a week like I just had.

Asynchronous Code Design with Node.js

You’re usually the lucky one if you get to fly off to any type of tech conference for a day or two while the rest of the team have to stay behind plugging away on that critical fix that needs to be pushed out to production – all because you committed a magic number into the repo just before you left which caused a stack overflow (since when is 34 in a recursive function a magic number anyway?). Continue reading Not Just About The Technology As a Senior Consultant at Shine Technologies here in Melbourne, Australia, I get to work on some great projects, with great technology and great people.

Continue reading Shine @ Google Cloud Live – Tuesday 25th March 2014 We were lucky enough to get an invite to the Google Cloud Live conference this year. Continue reading Shine Quoted in Google Cloud Platform Live Presentation Shine to film Google Developer Channel spot on BigQuery. Modules · joyent/node Wiki. Documentation. Util. Stability: 4 - API Frozen These functions are in the module 'util'.

Util

Use require('util') to access them. util.format(format, [ Perfection kills » Understanding delete. A couple of weeks ago, I had a chance to glance through Stoyan Stefanov’s Object-Oriented Javascript.

Perfection kills » Understanding delete

The book had an exceptionally high rating on Amazon (12 reviews with 5 stars), so I was curious to see if it was something worth recommending. I started reading through chapter on functions, and really enjoyed the way things were explained there; the flow of examples was structured in such nice, progressive way, it seemed even beginners would grasp it easily. However, almost immediately I stumbled upon an interesting misconception present throughout the entire chapter — deleting functions. There were some other mistakes (such as the difference between function declarations and function expressions), but we aren't going to talk about them now. The book claims that “function is treated as a normal variable—it can be copied to a different variable and even deleted.”.

>>> var sum = function(a, b) {return a + b;} >>> var add = sum; >>> delete sum true >>> typeof sum; "undefined" Theory§ Inheritance and Initialization in Node.js. Javascript inheritance is an interesting topic, rife with pitfalls for the unwary, and this is no less true in node.js than in any other modern application of Javascript.

Inheritance and Initialization in Node.js

For example, this is a common gotcha that I noted while translating thywill-python, an experiment-with-slash-exploration-of Comet frameworks, into node.js. Let's say I have a hierarchy of classes, A, B, and C, which extend out from EventEmitter as follows: The function util.inherits(subclass, superclass) is a shortcut for one of the methods of Javascript inheritance, provided in core node.js, and it looks like this under the hood: Events. Stability: 4 - API Frozen Many objects in Node emit events: a net.Server emits an event each time a peer connects to it, a fs.readStream emits an event when the file is opened.

Events

All objects which emit events are instances of events.EventEmitter. You can access this module by doing: require("events"); Typically, event names are represented by a camel-cased string, however, there aren't any strict restrictions on that, as any string will be accepted. Demystifying events in node.js. Static Version Ok, here's an important thing to understand when you're working with node.js.

Demystifying events in node.js

There're lots of node objects that emit events, and you can easily find some examples on the documentation. Taking Baby Steps with Node.js – Implementing Events. Here are the links to the previous installments: As I already mentioned in one of the previous posts, events lie at the heart of Node.js.

Taking Baby Steps with Node.js – Implementing Events

In fact, events ARE the heart of Node.js. When building our own custom modules, we are able to make use of this functionality provided by Node.js for emitting our very own events. We can do this by using the EventEmitter exposed by the built-in ‘events’ module. The following code snippet demonstrates how to use the simple API of the EventEmitter. How To Node - NodeJS. Prototypal Inheritance. Static Version In almost all modern programming languages we use the concept of Object Oriented Programming (OOP) to help manage the complexity of today's software.

Prototypal Inheritance

The biggest challenge in modern software is in fact managing the complexity of it. Most languages do this with a variant OOP called Classical OOP. This is the one you see in Java, C#, C++, PHP, Ruby, and Python. It has the idea that classes should be separate from instances. Asynchronous Control Flow with Promises. Static Version A Promise is an object that represents the result of an asynchronous function call.

Asynchronous Control Flow with Promises

Promises are also called futures and deferreds in some communities. Goal of this Article The goal of this article is to introduce CommonJS promises as they exist in NodeJS user-land. With jQuery popularizing a variant of CommonJS promises for AJAX operations, promises will likely gain a broader user-base in the browser and on the server. Understanding process.nextTick() Static Version.

Understanding process.nextTick()