background preloader

Mongoose ODM v3.1.2

Mongoose ODM v3.1.2

The Node Beginner Book » A comprehensive Node.js tutorial How To Node - NodeJS Express - guide Getting started With node installed (download), get your first application started by creating a directory somewhere on your machine: $ mkdir hello-world In this same directory you'll be defining the application "package", which are no different than any other node package. Now that you have a package.json file in this directory you can use npm(1) to install the dependencies, in this case just Express: $ npm install Once npm finishes you'll have a localized Express 3.x dependency in the . $ npm ls hello-world@0.0.1 /private/tmp └─┬ express@3.0.0beta7 ├── commander@0.6.1 ├─┬ connect@2.3.9 │ ├── bytes@0.1.0 │ ├── cookie@0.0.4 │ ├── crc@0.2.0 │ ├── formidable@1.0.11 │ └── qs@0.4.2 ├── cookie@0.0.3 ├── debug@0.7.0 ├── fresh@0.1.0 ├── methods@0.0.1 ├── mkdirp@0.3.3 ├── range-parser@0.0.4 ├─┬ response-send@0.0.1 │ └── crc@0.2.0 └─┬ send@0.0.3 └── mime@1.2.6 Now to create the application itself! var express = require('express'); var app = express(); Using express(1) to generate an app Then fire it up!

the cross-browser WebSocket for realtime apps. What is Socket.IO? Socket.IO aims to make realtime apps possible in every browser and mobile device, blurring the differences between the different transport mechanisms. It's care-free realtime 100% in JavaScript. Server Client How to use Installing npm install socket.io Using with Node HTTP server For this example, simply run `npm install socket.io` Server (app.js) Client (index.html) Using with the Express 3 web framework Express 3 requires that you instantiate a `http.Server` to attach socket.io to first: Using with the Express web framework You can serve normal pages and AJAX requests with Express, and attach your socket.io server For this example, simply run `npm install socket.io express` Sending and receiving events. Socket.IO allows you to emit and receive custom events. Storing data associated to a client Sometimes it's necessary to store data associated with a client that's necessary for the duration of the session. Restricting yourself to a namespace. Sending volatile messages. Desktop Mobile

blog.gvm-it.eu, Callback conventions in node.js, how and why Callback conventions in node.js, how and why When first confronted with node.js, you are not only presented with a completely new programming environment. You also encounter what is often referred to as callback hell accompanied by weird unfamiliar programming patterns. One of these is the way node treats callback functions. The following post explains the conventions that node.js uses for its callback patterns (referred to as Continuation-passing style) and how you should implement them in order to comply. The first argument is an error object Node expects - almost - all callback functions to accept an Error object as the first argument. There is a reason why this is a usefull pattern: Imagine, you have a chain of asynchroneous functions that were to execute one after the other. Now think something went wrong in the first function, i.e. the file cannot be read. This pattern lets you waterfall through function chains and leaves handling the error it up to the original invoking function.

Related: