nodeJS and Web APIs
57.7K views | +0 today
Follow
nodeJS and Web APIs
about node.js and Web APIs
Your new post is loading...
Your new post is loading...
Rescooped by Srdjan Strbanovic from JavaScript for Line of Business Applications
Scoop.it!

Build a Node API Client - Part 2: Encapsulation, Resources, & Architecture

Build a Node API Client - Part 2: Encapsulation, Resources, & Architecture | nodeJS and Web APIs | Scoop.it

Detailed How-To for building API Client libraries in Node.js. Client design and architecture using encapsulation and resources.


To achieve this, your Node.js client should only expose users to the public version of your API and never the private, internal implementation. If you’re coming from a more traditional Object Oriented world, you can think of the public API as behavior interfaces. Concrete implementations of those interfaces are encapsulated in the private API. In Node.js too, functions and their inputs and output should rarely change. Otherwise you risk breaking backwards compatibility.

Encapsulation creates lot of flexibility to make changes in the underlying implementation. 


Via Jan Hesse
more...
No comment yet.
Rescooped by Srdjan Strbanovic from JavaScript for Line of Business Applications
Scoop.it!

Fount - Dependency Injection for Node.js

Fount - Dependency Injection for Node.js | nodeJS and Web APIs | Scoop.it

My opinion on dependency injection (DI) for Node for years has been that it was unnecessary.

We can require this once during our service initialization and then require the same module to get the same instance anywhere it's needed. There are even simple ways to modify this pattern to make dependencies easy to stub or mock when testing.


Via Jan Hesse
more...
No comment yet.
Rescooped by Srdjan Strbanovic from JavaScript for Line of Business Applications
Scoop.it!

A Simple CRUD Demo with Koa.js

A Simple CRUD Demo with Koa.js | nodeJS and Web APIs | Scoop.it

In my previous blog post, I have introduced Koa.js, a new framework building Node.js apps, by leveraging harmony (ECMAScript 6) features of JavaScript. In this blog post, I will demonstrate how to write a web app in Koa.js with basic CRUD functionalities. The source code of the demo web app is available on Github.

In order to working with Koa.js, you must install Node 0.11.9 or higher for JavaScript generator support. After installing Node 0.11.9 or higher, you can install Koa.js using npm.

Koa is a minimalist framework and does not bundled with middleware, so that Koa itself, does not provide routing infrastructure. To use routing for Koa, you can use koa-route, which is a simple route middleware for Koa.


Via Jan Hesse
more...
No comment yet.
Rescooped by Srdjan Strbanovic from JavaScript for Line of Business Applications
Scoop.it!

Horizontally Scaling Node.js and WebSockets with Redis

Horizontally Scaling Node.js and WebSockets with Redis | nodeJS and Web APIs | Scoop.it

The Node.js cluster module is a common method of scaling servers, allowing for the use of all available CPU cores. However, what happens when you must scale to multiple servers or virtual machines?

That is the problem we faced when scaling our newest HTML5 MMORPG. Rather than trying to cluster on a single machine, we wanted to get the benefit of a truly distributed system that can automatically failover and spread the load across multiple servers and even data-centers.


Via Jan Hesse
more...
No comment yet.
Rescooped by Srdjan Strbanovic from JavaScript for Line of Business Applications
Scoop.it!

Managing Node.js Callback Hell with Promises, Generators and Other Approaches

Managing Node.js Callback Hell with Promises, Generators and Other Approaches | nodeJS and Web APIs | Scoop.it

Callback hell is subjective, as heavily nested code can be perfectly fine sometimes. Asynchronous code is hellish when it becomes overly complex to manage the flow. A good question to see how much “hell” you are in is: how much refactoring pain would I endure if doAsync2 happened before doAsync1?The goal isn’t about removing levels of indentation but rather writing modular (and testable!) code that is easy to reason about and resilient.

In this article, we will write a module using a number of tools and libraries to show how control flow can work. We’ll even look at an up and coming solution made possible by the next version of Node.

Let’s say we want to write a module that finds the largest file within a directory.

* A nested approach
* A modular approach
* An async approach
* A promises approach
* A generators approach



Via Jan Hesse
more...
No comment yet.