background preloader

Essential Node.js patterns and snippets

Essential Node.js patterns and snippets
In this post, I take a look at the different patterns that you need to know when using Node.js. These came from my own coding and from a look at the code behind Tim Caswell’s flow control libraries. I think it is necessary to know how these basic patterns are implemented even if you use a library.. 1.1 Class pattern If the class is long, then instead of doing a single Class.prototype = {…} assignment, it may be split into multiple Class.prototype.method = function () {..} assignments. Reminder: Assign all your properties some value in your constructor. 1.2 Accessing global values from objects // constructorvar Class = function(global, value2) { this.global = global;}// access using this.global in class methods 1.3 Factory pattern // Constructorvar Class = function(value1, value2) { ... }// FactoryClass.factory(value1) { return new Class(value1, "aaa"); }// properties and methodsClass.prototype = { ... }; 1.4 Sharing state between modules 1.5 Singleton class (added Feb 2011) 2.1 Parsing GET 4.

How To Node - NodeJS Top News - Echo JS The Node Beginner Book (Korean version) » A comprehensive Node.js tutorial 이 문서에 대하여 본 문서의 목표는 Node.js용 애플리케이션 개발을 시작을 할 수 있게 만드는 것입니다. 그리고 함께 알아야 하는 “고급” JavaScript에 관한 모든 것을 다룹니다. 본 문서는 전형적인 “Hello World” 튜토리얼 보다는 더 많이 다룹니다. 상태 당신은 현재 이 책의 최종버전을 읽고 있습니다. 이 책에 있는 코드 예제들은 Node.js 0.6.11에서 동작하는지 테스트 되었습니다. 대상 독자 이 문서는 저와 비슷한 배경을 가진 독자들에게 가장 잘 맞을 겁니다. 이미 다른 언어에 대한 경험을 가진 개발자들을 대상으로 한다는 말은 데이터 타입이나 변수, 제어구조 같은 것들을 이 문서에서 다루지 않다는 뜻입니다. 하지만, JavaScript에서의 객체나 함수들은 다른 대부분의 언어들에 대응되는 것과 다르기 때문에, 좀 더 자세히 설명하겠습니다. 이 문서의 구조 이 문서를 마치는 시점에, 유저들에게 웹페이지를 보여주고 파일들을 업로드 할 수 있는 완성된 웹 애플리케이션을 가지게 될 것입니다. 이 유스케이스를 만족하기 위해 “충분한 정도”까지만 코드를 만드는 것에서 조금 더 나아가서, “세상을 바꾸는 정도”는 아닙니다만, 간결하지만 완결성있는 프레임워크를 만들어서 우리의 애플리케이션의 다른 부분들로부터 깔끔하게 분리할 겁니다. 우리는 Node.js에서 JavaScript 개발을 하는 것이 브라우저에서 JavaScript를 개발하는 것과 어떻게 다른지를 살펴보는 것으로 시작하려 할겁니다. 다음으로, “Hello World” 애플리케이션을 작성하는 훌륭한 오랜 전통을 따를 생각입니다. 그리고 나서는, 우리가 만들기 원하는 “실제” 애플리케이션의 종류가 무엇인지에 대해 논의하고, 이 애플리케이션을 조립하기 위해 구현해야 하는 다른 부분들을 자세히 살펴보고, 하나씩 이 각각의 부분들에 대해 작업을 시작할 생각입니다. 완성된 애플리케이션의 소스코드는 아래 링크를 통해 다운 받으실 수 있습니다. 차례 JavaScript와 Node.js JavaScript와 당신 주의 사항

Javascript Version française You are about to download a document protected by copyright law in your country. The unauthorized reproduction or distribution of this copyrighted work is illegal and may be punishable by criminal law. The document is a single-user, non-revisable Adobe Acrobat® PDF file. You may print out and retain one-only printed copy of the PDF file. This printed copy is fully protected by national and international copyright laws, and may not be photocopied or reproduced in any form. While all reasonable care is taken in the preparation and review of ISO International Standards and other deliverables, ISO does not warrant that the content of the document is accurate or up to date or that the document will be suitable for your purposes. To the extent allowed in applicable law, in no event shall ISO be liable for any direct, indirect, punitive, incidental, special, consequential damages, or any damages whatsoever arising out of or connected with the use or misuse of this document.

CommonJS: JavaScript Standard Library Backbone.js Felix's Node.js Style Guide/en « Home / All Guides IMPORTANT: This version is outdated, the latest version is available on GitHub. There is no official document that governs the style of node.js applications. This guide is my opinionated attempt to bring you a good set of instructions that will allow you to create beautiful and consistent software. This guide assumes that you are only targeting node.js. If your code also needs to run in the browser or other environments, please ignore some of it. Please also note that node.js, as well as various packages for it, have their own slightly different styles. Tabs vs Spaces Let's start with the religious problems first. Semicolons There are rebellious forces that try to steal your semicolons from you. Editors You can use any editor. I'm typing this document in Notes on my iPad, but that's because I'm on a beach in Thailand. Trailing whitespace Just like you brush your teeth after every meal, you clean up any trailing whitespace in your JavaScript files before committing. Quotes

npm - Node Package Manager Packages/1.0 - CommonJS Spec Wiki Implementations JSBuild, PINF JS Loader, ArangoDB Packages This specification describes the CommonJS package format for distributing CommonJS programs and libraries. This specifies the CommonJS package descriptor file and package file format. Package Descriptor File Each package must provide a top-level package descriptor, "package.json". Required Fields Each package must provide all the following fields in its package descriptor file: name the name of the package. description a brief description of the package. version a version string conforming to the Semantic Versioning requirements ( keywords an Array of string keywords to assist users searching for the package in catalogs. maintainers Array of maintainers of the package. contributors an Array of hashes each containing the details of a contributor. bugs URL for submitting bugs. licenses array of licenses under which the package is provided. repositories Array of repositories where the package can be located. dependencies "os"

twich: php + node.js realtime web-based chat Twich was first mentioned back in July when the author, Isaac Su, posted a news item to Hacker News titled “I made a browser-based chat app. Based on node.js and nodechat.”. Yesterday (October 27, 2010), Isaac posted another news item to Hacker News titled “Remember twich.me (node.js realtime chat)? Here is the source as promised.”, officially open sourcing his code for all the world to see. Isaac does mention in the #readme that Twich is based on node_chat by Ryan Dahl Installation See the #readme for more details. www/ www/ is a set of php scripts that serve up the client files and organize the rooms. First, create a vhost in Apache and point it to this folder. Then, copy www/_config.php.sample to www/_config.php and enter your own configuration settings. var $port = 443; var $domain = ''; var $analyticsAccount = ''; var $analyticsDomainName = ''; Finally, edit .htaccess and put your own domain name in instead of twich.me Congrats www/ is all setup node/ node/ is the actual node server.

Related: