UNPKG

stackato-assist

Version:

A utility library for easy assistance in getting your node app running on Stackato.

133 lines (104 loc) 4.98 kB
<!DOCTYPE html><html><head><title>README</title><meta http-equiv="Content-Type" content="text/html" charset="UTF-8"><link rel="stylesheet" media="all" href="./docco.css"></head><body><div id="container"><div id="background"></div><div id="jump_to">Jump To &hellip;<div id="jump_wrapper"><div id="jump_page"><a href="./index.html" class="source"><span class="file_name">README</span></a><a href="././index.js.html" class="source "><span class="base_path">. / </span><span class="file_name">index.js</span></a></div></div></div><table cellpadding="0" cellspacing="0"><thead><tr><th class="docs"></th><th class="code"></th></tr></thead><tbody><tr id="section"><td class="docs"><h1><a href="http://jdpaton.github.com/stackato-assist">stackato-assist </a></h1><p>A utility library for easy assistance in getting your node app running on Stackato.</p><h3>Version</h3><p>0.0.5</p><h3>Author</h3><p>Jamie Paton</p><h3>Dependencies </h3><ul><li><b>mongodb </b><span>1.1.11</span></li><li><b>redis </b><span>0.8.2</span></li><li><b>pg </b><span>0.8.7</span></li><li><b>mysql </b><span>2.0.0-alpha4</span></li></ul><p><h3>Stats</h3><pre class="code_stats"> http://cloc.sourceforge.net v 1.55 T=0.5 s (2.0 files/s, 470.0 lines/s) ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- Javascript 1 47 38 150 ------------------------------------------------------------------------------- </pre></p></td><td id="content" class="code"><h1>Stackato-Assist</h1> <h2>A utility library for easy assistance in getting your node app running on Stackato.</h2> <h2>Install</h2> <pre><code>npm install stackato-assist </code></pre> <p>or add to your package.json dependencies.</p> <h2>Usage</h2> <pre><code>var stackato = require('stackato-assist'); if(stackato.isStackato){ // Basic App settings // ------------------ // listen port stackato.port // instance id stackato.instanceID // application host IP stackato.host // sudo enabled stackato.sudo // Registered application URIs for(uri in stackato.app.uris){ console.log(stackato.uris[uri]); } // User / Groups // -------------- // Users who have access to this app for(user in stackato.app.users){ console.log(stackato.users[user]); } // Group for this app stackato.app.group </code></pre> <h2>Services and database connection providers</h2> <p>Stackato-assist can easily provide database connections by only passing in the service name you gave when creating the service, or as defined in stackato.yml:</p> <pre><code> // Database services // ----------------- // true / false stackato.hasMongoDB stackato.hasRedis stackato.hasMySQL stackato.hasPostgreSQL // Get a service by name // --------------------- stackato.getService('myMongodb1', function(err, service){ console.log(service.host); console.log(service.db); // ... // }); // Persistent Filesystem service // ----------------------------- stackato.hasFileSystem // true/false stackato.fileSystemPath // /path/to/fs // Harbor external port service // ---------------------------- stackato.hasHarbor // true/false stackato.harborPort // port # // MongoDB connection helper // ------------------------- stackato.connectMongoDB('serviceName', function(err, client){ //client.collection(...) }); // Redis connection helper // ------------------------- stackato.connectRedis('serviceName', function(err, client){ //client.set("string key", "string val", redis.print); // ... }); // PostgreSQL connection helper // ------------------------- if(stackato.hasPostgreSQL){ stackato.connectPostgreSQL('x3p', function(err, client, pg){ client.query("SELECT NOW() as when", function(err, result) { console.log("Row count: %d",result.rows.length); // 1 console.log("Current year: %d", result.rows[0].when.getFullYear()); pg.connect(function(err, clientTwo){ // clientTwo.query(...) a new client object using connection params already set // by stackato-assist }); //pg.end(); //terminate the client pool, disconnecting all clients }); }); } // MySQL connection helper // ------------------------- if(stackato.hasMySQL){ stackato.connectMySQL('x4m', function(err, conn){ connection.query('SELECT 1 + 1 AS solution', function(err, rows, fields) { if (err) throw err; console.log('The solution is: ', rows[0].solution); }); // connection.end(); }); } </code></pre> </td></tr></tbody></table><div id="generated">generated Mon May 20 2013 22:52:33 GMT-0700 (PDT) </div><div id="projectname"><a href="./index.html">Stackato-Assist</a></div></div></body></html>