### Download and Execute Quickstart Script
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/README-cloud.md
Use these commands to download, make executable, and run the UrbanFootprint quickstart script. Expect the installation to take 15-20 minutes.
```bash
wget https://raw.githubusercontent.com/CalthorpeAnalytics/urbanfootprint/master/quickstart.sh
chmod +x quickstart.sh
sudo ./quickstart.sh
```
--------------------------------
### Run an Express Example
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/Readme.md
After cloning the repository and installing dependencies, you can run specific examples by navigating to the express directory and executing this command.
```bash
$ node examples/content-negotiation
```
--------------------------------
### Download Vagrantfile and Start VM
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/README-developers-windows.md
Use Git Bash to download the Windows-specific Vagrantfile and initiate the virtual machine setup.
```bash
wget -O Vagrantfile https://raw.githubusercontent.com/CalthorpeAnalytics/urbanfootprint/master/Vagrantfile-windows
vagrant up
vagrant ssh
```
--------------------------------
### Basic Express.js Server Setup
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/Readme.md
This snippet demonstrates the fundamental setup for an Express.js server, including requiring the module, creating an app instance, defining a root route, and starting the server on port 3000.
```javascript
var express = require('express')
var app = express()
app.get('/', function (req, res) {
res.send('Hello World')
})
app.listen(3000)
```
--------------------------------
### Install Debug Module
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/debug/README.md
Install the debug module using npm. This is the initial setup step for using the library.
```bash
$ npm install debug
```
--------------------------------
### Clone Express Repository and Install Dependencies
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/Readme.md
To explore examples, clone the Express repository and install its dependencies.
```bash
$ git clone git://github.com/expressjs/express.git --depth 1
$ cd express
$ npm install
```
--------------------------------
### Install component-bind
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/socket.io/node_modules/socket.io-client/node_modules/component-bind/Readme.md
Install the component-bind utility using component.
```bash
component install component/bind
```
--------------------------------
### Start the Express Application
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/Readme.md
This command starts the Express development server after dependencies have been installed.
```bash
$ npm start
```
--------------------------------
### Install ws
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/socket.io/node_modules/engine.io/node_modules/ws/README.md
Install the ws library using npm.
```bash
npm install --save ws
```
--------------------------------
### Install UrbanFootprint VM Locally
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/README.md
Use this command to download and execute a script that sets up a local UrbanFootprint virtual machine. This is the quickest way to get a local instance running.
```bash
curl https://raw.githubusercontent.com/CalthorpeAnalytics/urbanfootprint/master/get-uf.sh | bash
```
--------------------------------
### Install component-inherit
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/component-inherit/Readme.md
Install the library using the component package manager.
```bash
component install component/inherit
```
--------------------------------
### Install EE First
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/on-finished/node_modules/ee-first/README.md
Install the ee-first module using npm.
```sh
npm install ee-first
```
--------------------------------
### Install Bundler and Project Gems
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/README-developers.md
Install the Bundler gem and then install all project dependencies using Bundler, configuring it to use OpenSSL include paths for eventmachine.
```bash
eval "$(rbenv init -)"
gem install bundler
bundle config build.eventmachine --with-cppflags=-I`brew --prefix openssl`/include
bundle install
```
--------------------------------
### Install Send via npm
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/send/README.md
Install the send library using the npm install command.
```bash
npm install send
```
--------------------------------
### Install on-finished
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/on-finished/README.md
Install the on-finished module using npm.
```sh
$ npm install on-finished
```
--------------------------------
### Install fresh module
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/fresh/README.md
Install the fresh module using npm.
```bash
npm install fresh
```
--------------------------------
### Initialize Yeast
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/yeast/README.md
Require the yeast module in your JavaScript file. This setup is assumed for all subsequent examples.
```javascript
'use strict';
var yeast = require('yeast');
```
--------------------------------
### Install and Basic Usage
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/redis/node_modules/double-ended-queue/README.md
Install the library using npm and perform basic operations like shifting and popping elements.
```javascript
var Deque = require("double-ended-queue");
var deque = new Deque([1,2,3,4]);
deque.shift(); //1
deque.pop(); //4
```
--------------------------------
### Install setprototypeof
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/setprototypeof/README.md
Install the package using npm.
```bash
npm install --save setprototypeof
```
--------------------------------
### Install methods module
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/methods/README.md
Install the methods module using npm.
```bash
$ npm install methods
```
--------------------------------
### Install serve-static with npm
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/serve-static/README.md
Install the serve-static module using the npm package manager.
```sh
$ npm install serve-static
```
--------------------------------
### Install Backo2
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/socket.io/node_modules/socket.io-client/node_modules/backo2/Readme.md
Install the backo2 package using npm.
```bash
npm install backo
```
--------------------------------
### Install isarray with component
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/socket.io/node_modules/has-binary/node_modules/isarray/README.md
Install the 'isarray' package using the component package manager.
```bash
$ component install juliangruber/isarray
```
--------------------------------
### More Examples Addition
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/History.md
Adds more examples to the documentation.
```javascript
Added more examples
```
--------------------------------
### Install content-disposition
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/content-disposition/README.md
Install the package using npm.
```sh
npm install content-disposition
```
--------------------------------
### Install media-typer
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/type-is/node_modules/media-typer/README.md
Install the media-typer module using npm.
```sh
npm install media-typer
```
--------------------------------
### Install proxy-addr
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/proxy-addr/README.md
Install the proxy-addr module using npm.
```sh
npm install proxy-addr
```
--------------------------------
### Install Negotiator
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/accepts/node_modules/negotiator/README.md
Install the negotiator module using npm.
```sh
npm install negotiator
```
--------------------------------
### Install encodeurl
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/encodeurl/README.md
Install the encodeurl module using npm.
```sh
npm install encodeurl
```
--------------------------------
### Install type-is
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/type-is/README.md
Install the type-is module using npm.
```sh
$ npm install type-is
```
--------------------------------
### Install accepts Module
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/accepts/README.md
Install the accepts module using npm.
```sh
npm install accepts
```
--------------------------------
### Install component/emitter
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/socket.io/node_modules/socket.io-client/node_modules/component-emitter/Readme.md
Install the emitter component using the component package manager.
```bash
$ component install component/emitter
```
--------------------------------
### Install isarray with npm
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/socket.io/node_modules/has-binary/node_modules/isarray/README.md
Install the 'isarray' package using npm for use in Node.js projects or for browserification.
```bash
$ npm install isarray
```
--------------------------------
### Install parseurl
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/parseurl/README.md
Install the parseurl package using npm.
```bash
$ npm install parseurl
```
--------------------------------
### Install Application Dependencies
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/Readme.md
After creating a new Express application, run this command to install all its project dependencies.
```bash
$ npm install
```
--------------------------------
### Install wtf-8 via Component
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/socket.io/node_modules/engine.io/node_modules/engine.io-parser/node_modules/wtf-8/README.md
Use Component to install the wtf-8 package.
```bash
component install mathiasbynens/wtf-8
```
--------------------------------
### Install array-flatten
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/array-flatten/README.md
Install the array-flatten package using npm.
```bash
npm install array-flatten --save
```
--------------------------------
### Install content-type Package
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/content-type/README.md
Install the content-type package using npm.
```sh
npm install content-type
```
--------------------------------
### Install Engine.IO Dependencies
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/socket.io/node_modules/engine.io/README.md
After cloning the repository, navigate to the engine.io directory and install the necessary dependencies using npm.
```bash
cd engine.io
npm install
```
--------------------------------
### Install Express.js
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/Readme.md
Use this command to install the Express.js package via npm.
```bash
$ npm install express
```
--------------------------------
### Install Yeast
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/yeast/README.md
Install the yeast module using npm. This command saves the dependency to your package.json.
```bash
npm install --save yeast
```
--------------------------------
### Run UrbanFootprint Quickstart Script
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/README-developers-windows.md
Execute the quickstart script within the guest VM to set up a pre-built database and run services in production mode.
```bash
./quickstart.sh
```
--------------------------------
### Install mime-db Package
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/accepts/node_modules/mime-types/node_modules/mime-db/README.md
Install the mime-db package using npm. This command is used for project setup.
```bash
npm install mime-db
```
--------------------------------
### Install better-assert
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/parsejson/node_modules/better-assert/Readme.md
Install the better-assert package using npm. This command should be run in your project's terminal.
```bash
$ npm install better-assert
```
--------------------------------
### Configure Development Database
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/README-developers.md
Set up the development database by copying the sample environment file, downloading the database dump, creating a new database, and importing the data.
```bash
cp .env.sample .env
wget https://s3-us-west-2.amazonaws.com/uf-provisioning/urbanfootprint-sacog-source-db.sql.gz
gunzip urbanfootprint-sacog-source-db.sql.gz
psql -U postgres -c "DROP DATABASE IF EXISTS urbanfootprint_sacog_source;"
psql -U postgres -c "CREATE DATABASE urbanfootprint_sacog_source;"
psql -U postgres urbanfootprint_sacog_source < urbanfootprint-sacog-source-db.sql
```
--------------------------------
### Install rbenv and Ruby Version
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/README-developers.md
Install rbenv and a specific Ruby version (1.9.3-p551) on Mac OS X, with OpenSSL support. This is a one-time setup.
```bash
cd ~/src/urbanfootprint
git pull
CONFIGURE_OPTS=--with-openssl-dir=`brew --prefix openssl` rbenv install 1.9.3-p551
```
--------------------------------
### Execute Pipelined Commands in C
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/hiredis/deps/hiredis/README.md
After appending commands using redisAppendCommand or redisAppendCommandArgv, call redisGetReply to retrieve replies. This example shows retrieving replies for a SET and a GET command.
```c
redisReply *reply;
redisAppendCommand(context,"SET foo bar");
redisAppendCommand(context,"GET foo");
redisGetReply(context,&reply); // reply for SET
freeReplyObject(reply);
redisGetReply(context,&reply); // reply for GET
freeReplyObject(reply);
```
--------------------------------
### Basic File Serving Example
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/send/README.md
A simple example demonstrating how to serve files using the send module. It creates an HTTP server that serves files based on the request URL's pathname.
```javascript
var http = require('http')
var parseUrl = require('parseurl')
var send = require('send')
var server = http.createServer(function onRequest (req, res) {
send(req, parseUrl(req).pathname).pipe(res)
})
server.listen(3000)
```
--------------------------------
### Parser Initialization and Usage
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/redis/node_modules/redis-parser/README.md
Demonstrates how to instantiate the Parser with required callback functions and how to execute incoming data.
```APIDOC
## Parser Initialization and Usage
### Description
Instantiate the Parser with mandatory `returnReply` and `returnError` callbacks, and an optional `returnFatalError` callback. The `execute` method processes incoming buffer data.
### Constructor
`new Parser(options)`
### Options
* `returnReply`: *function*; mandatory - Callback for successful replies.
* `returnError`: *function*; mandatory - Callback for errors.
* `returnFatalError`: *function*; optional - Callback for fatal errors.
* `returnBuffers`: *boolean*; optional, defaults to `false` - If true, replies are returned as Buffers.
* `stringNumbers`: *boolean*; optional, defaults to `false` - If true, numbers are returned as Strings.
### Methods
* `execute(buffer)`: Processes a buffer of data.
### Example
```js
var Parser = require("redis-parser");
function Library () {}
Library.prototype.returnReply = function (reply) { console.log(reply); };
Library.prototype.returnError = function (err) { console.error(err); };
Library.prototype.returnFatalError = function (err) { console.error(err); };
var lib = new Library();
var parser = new Parser({
returnReply: function(reply) {
lib.returnReply(reply);
},
returnError: function(err) {
lib.returnError(err);
},
returnFatalError: function (err) {
lib.returnFatalError(err);
}
});
// Example of processing data from a stream
// Assume 'buffer' contains data from a Redis stream
// parser.execute(buffer);
```
```
--------------------------------
### Enable All Except Specific Namespaces
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/finalhandler/node_modules/debug/README.md
Use wildcards and exclusion patterns in the __DEBUG__ environment variable to enable most debuggers while excluding specific ones. This example enables all debuggers except those starting with 'connect:'.
```bash
DEBUG=*,-connect:*
node your_app.js
```
--------------------------------
### Browserify Integration for Payload Handling
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/engine.io-parser/Readme.md
Shows how to install and use engine.io-parser with browserify for handling payloads, including binary data. The example illustrates encoding a payload with mixed data types and decoding it, processing binary data as Int8Array.
```shell
npm install engine.io-parser
```
```javascript
var parser = require('engine.io-parser');
var testBuffer = new Int8Array(10);
for (var i = 0; i < testBuffer.length; i++) testBuffer[i] = i;
var packets = [{ type: 'message', data: testBuffer.buffer }, { type: 'message', data: 'hello' }];
parser.encodePayload(packets, function(encoded) {
parser.decodePayload(encoded,
function(packet, index, total) {
var isLast = index + 1 == total;
if (!isLast) {
var buffer = new Int8Array(packet.data); // testBuffer
} else {
var message = packet.data; // 'hello'
}
});
});
```
```bash
$ browserify app.js > bundle.js
```
```html
```
--------------------------------
### Install, Test, and Benchmark Redis Parser
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/redis/node_modules/redis-parser/README.md
Standard commands for setting up the project, running tests, and executing performance benchmarks.
```bash
npm install
npm test
npm run benchmark
```
--------------------------------
### Node.js Options.js Usage Example
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/ws/node_modules/options/README.md
Demonstrates how to create, merge, reset, copy, read, and check options using the Options object. Includes both synchronous and asynchronous file reading.
```javascript
var Options = require("options");
// Create an Options object
function foo(options) {
var default_options = {
foo : "bar"
};
// Create an option object with default value
var opts = new Options(default_options);
// Merge options
opts = opts.merge(options);
// Reset to default value
opts.reset();
// Copy selected attributes out
var seled_att = opts.copy("foo");
// Read json options from a file.
opts.read("options.file"); // Sync
opts.read("options.file", function(err){
if(err){
console.log("File error.");
}else{
// No error
}
});
// Attributes defined or not
opts.isDefinedAndNonNull("foobar");
opts.isDefined("foobar");
}
```
--------------------------------
### Install etag Module
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/etag/README.md
Install the etag module using npm. This command downloads and installs the package into your project.
```sh
npm install etag
```
--------------------------------
### Install depd module
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/depd/Readme.md
Install the depd module using npm. This command installs the module and adds it to your project's dependencies.
```sh
npm install depd
```
--------------------------------
### Server Initialization and Event Handling
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/socket.io/node_modules/engine.io/README.md
Demonstrates how to initialize an Engine.IO server and handle incoming connections and messages.
```APIDOC
## Server Initialization
### (A) Listening on a port
```js
var engine = require('engine.io');
var server = engine.listen(80);
server.on('connection', function(socket){
socket.send('utf 8 string');
socket.send(new Buffer([0, 1, 2, 3, 4, 5])); // binary data
});
```
### (B) Intercepting requests for a http.Server
```js
var engine = require('engine.io');
var http = require('http').createServer().listen(3000);
var server = engine.attach(http);
server.on('connection', function (socket) {
socket.on('message', function(data){ });
socket.on('close', function(){ });
});
```
### (C) Passing in requests
```js
var engine = require('engine.io');
var server = new engine.Server();
server.on('connection', function(socket){
socket.send('hi');
});
// …
httpServer.on('upgrade', function(req, socket, head){
server.handleUpgrade(req, socket, head);
});
httpServer.on('request', function(req, res){
server.handleRequest(req, res);
});
```
```
--------------------------------
### Socket.IO Server Initialization Variants
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/socket.io/Readme.md
Demonstrates different ways to instantiate the Socket.IO Server, including standalone and with an existing HTTP server.
```javascript
var io = require('socket.io')();
```
```javascript
var Server = require('socket.io');
var io = new Server();
```
--------------------------------
### Instantiate Engine.IO Server and Attach
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/socket.io/node_modules/engine.io/README.md
Demonstrates multiple ways to instantiate an Engine.IO Server and attach it to an existing Node.js http.Server.
```javascript
var httpServer; // previously created with `http.createServer();` from node.js api.
// create a server first, and then attach
var eioServer = require('engine.io').Server();
eioServer.attach(httpServer);
// or call the module as a function to get `Server`
var eioServer = require('engine.io')();
eioServer.attach(httpServer);
// immediately attach
var eioServer = require('engine.io')(httpServer);
```
--------------------------------
### Install redis-commands
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/redis/node_modules/redis-commands/README.md
Install the redis-commands module using npm.
```shell
$ npm install redis-commands
```
--------------------------------
### Initialize and Activate Node.js Environment
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/README.md
Use these commands to set up a dedicated Node.js environment and activate it before installing packages.
```bash
nodeenv /srv/calthorpe_websockets_env
```
```bash
. /srv/calthorpe_websockets_env/bin/activate
```
--------------------------------
### Run Tests
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/utils-merge/README.md
Install dependencies and run tests for utils-merge.
```bash
npm install
npm test
```
--------------------------------
### Install utils-merge
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/utils-merge/README.md
Install the utils-merge package using npm.
```bash
npm install utils-merge
```
--------------------------------
### Simple Type Negotiation Example
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/accepts/README.md
This example demonstrates how to use accepts to negotiate the response content type based on the client's Accept header. The server's preferred types are listed in order, and the best match is returned.
```js
var accepts = require('accepts')
var http = require('http')
function app(req, res) {
var accept = accepts(req)
// the order of this list is significant; should be server preferred order
switch(accept.type(['json', 'html'])) {
case 'json':
res.setHeader('Content-Type', 'application/json')
res.write('{"hello":"world!"}')
break
case 'html':
res.setHeader('Content-Type', 'text/html')
res.write('hello, world!')
break
default:
// the fallback is text/plain, so no need to specify it above
res.setHeader('Content-Type', 'text/plain')
res.write('hello, world!')
break
}
res.end()
}
http.createServer(app).listen(3000)
```
--------------------------------
### Install range-parser
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/range-parser/README.md
Install the range-parser module using npm.
```bash
$ npm install range-parser
```
--------------------------------
### Basic Redis Client Usage
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/redis/README.md
Demonstrates how to create a Redis client, handle errors, and execute basic commands like SET, HSET, and HKEYS. Commands are executed asynchronously with callbacks.
```javascript
var redis = require("redis"),
client = redis.createClient();
// if you'd like to select database 3, instead of 0 (default), call
// client.select(3, function() { /* ... */ });
client.on("error", function (err) {
console.log("Error " + err);
});
client.set("string key", "string val", redis.print);
client.hset("hash key", "hashtest 1", "some value", redis.print);
client.hset(["hash key", "hashtest 2", "some other value"], redis.print);
client.hkeys("hash key", function (err, replies) {
console.log(replies.length + " replies:");
replies.forEach(function (reply, i) {
console.log(" " + i + ": " + reply);
});
client.quit();
});
```
--------------------------------
### Install forwarded
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/proxy-addr/node_modules/forwarded/README.md
Install the forwarded module using npm.
```sh
npm install forwarded
```
--------------------------------
### Server Initialization
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/socket.io/Readme.md
Demonstrates different ways to initialize a Socket.IO server, either standalone or attached to an existing HTTP server.
```APIDOC
## Server Initialization
### Standalone
```js
var io = require('socket.io')();
io.on('connection', function(client){});
io.listen(3000);
```
### With Node.JS HTTP Server
```js
var server = require('http').createServer();
var io = require('socket.io')(server);
io.on('connection', function(client){
client.on('event', function(data){});
client.on('disconnect', function(){});
});
server.listen(3000);
```
### With Express.JS
```js
var app = require('express')();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
io.on('connection', function(){ /* ... */ });
server.listen(3000);
```
### With Koa.JS
```js
var app = require('koa')();
var server = require('http').createServer(app.callback());
var io = require('socket.io')(server);
io.on('connection', function(){ /* ... */ });
server.listen(3000);
```
```
--------------------------------
### Import Path-to-RegExp
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/path-to-regexp/Readme.md
Import the path-to-regexp module using require. This is the initial setup step for using the library.
```javascript
var pathToRegexp = require('path-to-regexp');
```
--------------------------------
### Install unpipe
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/finalhandler/node_modules/unpipe/README.md
Install the unpipe module using npm.
```sh
npm install unpipe
```
--------------------------------
### Install finalhandler
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/finalhandler/README.md
Install the finalhandler module using npm.
```sh
npm install finalhandler
```
--------------------------------
### Install and Configure Nginx
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/README-developers.md
Install Nginx using Homebrew, remove the default configuration, create a log directory, and link the UrbanFootprint Nginx configuration file.
```bash
brew install nginx
rm /usr/local/etc/nginx/nginx.conf
sudo mkdir /var/log/nginx
sudo touch /var/log/nginx/uf_dev.log
ln -s `pwd`/conf/etc/nginx/sites-available/calthorpe.nginx.osx /usr/local/etc/nginx/nginx.conf
```
--------------------------------
### Install Python Dependencies and Build Project
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/README-developers.md
Install the required Python packages using pip and then build the development version of the project using Fabric.
```bash
pip install -r requirements.txt
fab -f footprint/installer localhost build:dev
```
--------------------------------
### Server Constructor
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/socket.io/node_modules/engine.io/README.md
Initializes the Engine.IO server with optional configuration.
```APIDOC
## constructor(options)
### Description
Initializes the server with optional configuration settings.
### Parameters
- `options` (Object): Optional configuration object.
### Options
- `pingTimeout` (Number): Timeout in ms for considering a connection closed without a pong packet. Default: `60000`.
- `pingInterval` (Number): Interval in ms before sending a new ping packet. Default: `25000`.
- `upgradeTimeout` (Number): Timeout in ms before cancelling an uncompleted transport upgrade. Default: `10000`.
- `maxHttpBufferSize` (Number): Maximum bytes or characters for a message in polling, to prevent DoS. Default: `10E7`.
- `allowRequest` (Function): Function to decide whether to continue a handshake or upgrade request. Receives `(request, callback)` where `callback(err, success)` determines the outcome.
- `transports` (Array): Allowed connection transports. Default: `['polling', 'websocket']`.
- `allowUpgrades` (Boolean): Whether to allow transport upgrades. Default: `true`.
- `perMessageDeflate` (Object|Boolean): WebSocket permessage-deflate extension parameters. Set to `false` to disable. Default: `true`.
- `threshold` (Number): Minimum byte size for data compression. Default: `1024`.
- `httpCompression` (Object|Boolean): HTTP compression parameters for polling transports. Set to `false` to disable. Default: `true`.
- `threshold` (Number): Minimum byte size for data compression. Default: `1024`.
- `cookie` (String|Boolean): Name of the HTTP cookie for client sid in handshake response headers. Set to `false` to disable. Default: `'io'`.
- `cookiePath` (String|Boolean): Path for the `cookie` option. Set to `false` to not send a path. Default: `'/'`.
- `cookieHttpOnly` (Boolean): If `true`, the `HttpOnly` cookie cannot be accessed by client-side APIs. Default: `true`. (Has no effect if `cookie` or `cookiePath` is `false`.)
- `wsEngine` (String): WebSocket server implementation to use. Must conform to the `ws` interface. Default: `'ws'`.
```
--------------------------------
### Publish/Subscribe Example
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/redis/README.md
Demonstrates the publish/subscribe API by opening two client connections. One client subscribes to a channel, and the other publishes messages to it. This is useful for real-time messaging between different parts of an application or different services.
```javascript
var redis = require("redis");
var sub = redis.createClient(), pub = redis.createClient();
var msg_count = 0;
sub.on("subscribe", function (channel, count) {
pub.publish("a nice channel", "I am sending a message.");
pub.publish("a nice channel", "I am sending a second message.");
pub.publish("a nice channel", "I am sending my last message.");
});
sub.on("message", function (channel, message) {
console.log("sub channel " + channel + ": " + message);
msg_count += 1;
if (msg_count === 3) {
sub.unsubscribe();
sub.quit();
pub.quit();
}
});
sub.subscribe("a nice channel");
```
--------------------------------
### Install cookie package
Source: https://github.com/calthorpeanalytics/urbanfootprint/blob/master/websockets/node_modules/express/node_modules/cookie/README.md
Install the cookie package using npm.
```sh
npm install cookie
```