How to use resource - 10 common examples

To help you get started, we’ve selected a few resource examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bigcompany / mesh / examples / 1_resource-events / creature.js View on Github external
var resource = require('resource');

var creature = resource.define('creature');
// TODO: make remote a getter / setter that updates event table
creature.remote = true;

// TODO: add granular controls for remote methods
// so that entire resource isn't exposed
creature.method('talk', function(options, callback){
  console.log('talking', options)
  callback(null, options.text);
});

module['exports'].creature = creature;
github bigcompany / resources / mesh / index.js View on Github external
//
// The mesh allows big to communicate with other big instances
//
var resource = require('resource'),
    mesh = resource.define('mesh');

mesh.schema.description = "provides a distributed p2p event emitter mesh";

resource.use('node', { datasource: 'fs' });
resource.use('system');
resource.use('http');

var emit, meshEmitter;
function events() {
  if (emit && meshEmitter) {
    return;
  }

  var EventEmitter = require('eventemitter2').EventEmitter2;

  //
github bigcompany / resources / socket / index.js View on Github external
var resource  = require('resource'),
    socket = resource.define('socket');

socket.schema.description = "websockets resource";

socket.method('start', start, {
  "description": "starts a websocket server",
  "properties": {
    "callback": {
      "description": "the callback executed after server listen",
      "type": "function",
      "required": false
    }
  }
});

//
// Available websocket engines
github bigcompany / safewallet / lib / resources / prices.js View on Github external
var BigNumber = require('bignumber.js'),
    resource = require('resource'),
    request = require('request'),
    prices = resource.define('prices');

prices.property('prices', 'object');
prices.description = "calculates estimated market prices of coins";
prices.timestamps();

prices.method('fetch', function (callback){
  var _prices = {};
  // Get BTC price
  request.get({ url: 'https://btc-e.com/api/2/btc_usd/trades', method: "GET" }, function (err, resp, body){
    var btcPrice = JSON.parse(body);
    btcPrice = btcPrice[0].price.toString();
    _prices['bitcoin'] = btcPrice;
    // Get peercoin price
    request.get({ url: 'https://btc-e.com/api/2/ppc_usd/trades', method: "GET" }, function (err, resp, body){
      var ppcPrice = JSON.parse(body);
      ppcPrice = ppcPrice[0].price.toString();
github bigcompany / mesh / examples / 0_basic / client.js View on Github external
var mesh = require('../../');
var resource = require('resource');
var creature = resource.define('creature');

require('colors')
/*
creature.method('talk', function(options, cb){
  console.log('creature talked', options.text.green)
  cb(null, options.text);
});
*/

mesh.connect({ port: 7777, name: "test-client" }, function(err){

  if (err) { 
    console.log('error connecting to mesh server. most likely the server is not running.', err);
    process.exit();
  }
github bigcompany / resources / stdout / index.js View on Github external
var resource = require('resource'),
    stdout = resource.define('stdout');

stdout.schema.description = "outputs all events as new-line delimited JSON fragments to STDOUT";

resource.onAny(function(data){
  data = data || {};
  var obj = {
    "event": this.event,
    "data": data
  };
  //console.log(JSON.stringify(obj));
});

exports.stdout = stdout;
github bigcompany / resources / memory / index.js View on Github external
var resource = require('resource'),
    memory = resource.define('memory');

memory.schema.description = "enables memory persistence";

exports.memory = memory;
github bigcompany / resources / bitcoin / index.js View on Github external
var resource = require('resource'),
    bitcoin = resource.define('bitcoin');

bitcoin.schema.description = 'for managing bitcoins';

bitcoin.property('server', {
  description: 'a bitcoin server',
  properties: {
    host: {
      description: 'the hostname of the bitcoin server',
      type: 'string',
      default: 'localhost'
    },
    port: {
      description: 'the port of the bitcoin server',
      type: 'number',
      default: 8332
    },
github bigcompany / safewallet / lib / resources / metrics.js View on Github external
var resource = require('resource'),
    metrics = resource.define('metrics');

metrics.property('wallets', { type: "number", required: true, default: 0 });
metrics.property('peercoin', { type: "string", required: true, default: "0.00"  });
metrics.property('bitcoin', { type: "string", required: true, default: "0.00"  });
metrics.property('litecoin', { type: "string", required: true, default: "0.00"  });
metrics.property('dogecoin', { type: "string", required: true, default: "0.00"  });
metrics.property('dollars', { type: "string", required: true, default: "0.00" });

metrics.timestamps();

exports.metrics = metrics;
github bigcompany / big / resources / video / index.js View on Github external
var resource = require('resource'),
    video = resource.define('video');

video.schema.description = "for managing online digital videos";

video.property("title", {
  "type":"string",
  "default": "my title",
  "description": "the title of the video"
});

video.property("link", {
  "type":"string",
  "description": "the link to the video on a third party site",
  "format": "url"
});

video.property("description", {

resource

node.js resource library

MIT
Latest version published 8 years ago

Package Health Score

49 / 100
Full package analysis

Popular resource functions