How to use node - 10 common examples

To help you get started, we’ve selected a few node 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 WP-API / node-wpapi / lib / pages.js View on Github external
/**
	 * @property _supportedMethods
	 * @type Array
	 * @private
	 * @default [ 'head', 'get', 'post' ]
	 */
	this._supportedMethods = [ 'head', 'get', 'post' ];

	// Default all .pages() requests to assume a query against the WP API v2 endpoints
	this.namespace( 'wp/v2' );
}

inherit( PagesRequest, CollectionRequest );

// Mixins
extend( PagesRequest.prototype, pick( filters, [
	// Specify that we are requesting a page by its path
	'path'
] ) );

/**
 * A hash table of path keys and regex validators for those path elements
 *
 * @property _pathValidators
 * @type Object
 * @private
 */
PagesRequest.prototype._pathValidators = {

	// No validation on "id", since it can be a string path OR a numeric ID

	/**
github mmoulton / crawl / lib / jobs / crawl.js View on Github external
/*!
 * Crawl - node.io crawl job
 * Copyright(c) 2012 Mike Moulton 
 * MIT Licensed
 */

var nodeio = require('node.io'),
    first = require('first'),
    urlUtil = require('url'),
    hash = require('node_hash'),
    util = require('util'),
    _ = require('underscore'),
    ct = require('../content-type');

var crawl = exports.job = new nodeio.Job({max: 50, retries: 3, auto_retry: true, timeout: 30}, {

  init: function() {
    this.options.cache = {};
    this.options.baseUrl = undefined;
  },

  run: function (url) {

    this.options.crawler.emit("crawl", url);

    var urlParts = urlUtil.parse(url, true);

    // Remember the first URL crawled so we can restrict all mined links to the same host
    if (!this.options.baseUrl) {
      this.options.baseUrl = urlParts;
    }
github node-js-libs / node.io / examples / google_pagerank.js View on Github external
if (!~data.indexOf('Rank_1:1:')) {
                self.emit(input+',');
            } else {
                self.emit(input+','+data.substr(9));
            }
        });        
    }, 
    
    fail: function(input) {
        this.emit(input+',');
    }

};

//Export the job
exports.job = new Job(options, methods);

//-----------------------------------------------
// CODE FOR GENERATING GOOGLE PAGERANK CHECKSUMS
//-----------------------------------------------

function zF(a,b) {
    var z = parseInt(80000000,16);
    if (z & a) {
        a = a>>1;
        a &=~z;
        a |= 0x40000000;
        a = a>>(b-1);
    } else {
        a = a>>b;
    }
    return(a);
github Glench / Capstone-Tank-Robot-Software / webserver / app.js View on Github external
var start_job = function(job) {
            nodeio.start(job, function (err, output) {
                if (!err) {
                    // not sure why this sends an array
                    sio.sockets.emit('repeater_strength', output[0])
                } else {
                    sio.sockets.emit('repeater_strength', err)
                }
            }, true);
        };
        start_job(job1);
github kevinflo / twitchplayscrypto / app / server.js View on Github external
var secrets = require('../config/secrets.json');
var config = require('../config/chatConfig.js');
var bittrex = require('node.bittrex.api');

// express stuff
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var lessMiddleware = require('less-middleware');
var _ = require('lodash');
var fs = require('fs');

bittrex.options({
    'apikey': secrets.bittrex.API_KEY,
    'apisecret': secrets.bittrex.API_SECRET,
});

fs.writeFile('logs/votes.txt', "", { flag: 'wx' }, function (err) {
    if (err) console.log(err);
    console.log("votes saved!");
});

fs.writeFile('logs/orders.txt', "", { flag: 'wx' }, function (err) {
    if (err) console.log(err);
    console.log("orders saved!");
});

fs.writeFile('logs/balances.txt', "", { flag: 'wx' }, function (err) {
    if (err) console.log(err);
github koopjs / koop-core / api / providers / socrata / controller / index.js View on Github external
var extend = require('node.extend'),
  fs = require('fs'),
  crypto = require('crypto'),
  base = require('../../base/controller.js');

// inherit from base controller
var Controller = extend({
  serviceName: 'socrata',

  register: function(req, res){
    if ( !req.body.host ){
      res.send('Must provide a host to register:', 500); 
    } else { 
      Socrata.register( req.body.id, req.body.host, function(err, id){
        if (err) {
          res.send( err, 500);
        } else {
          res.json({ 'serviceId': id });
        }
    });
    }
  },
github kissyteam / kissy / build / menu-debug.js View on Github external
], function (S, require, exports, module) {
    /**
 * @ignore
 * submenu control for kissy, transfer item's keyCode to menu
 * @author yiminghe@gmail.com
 */
    var util = require('util');
    var SubMenuTpl = require('./submenu-xtpl');
    var MenuItem = require('./menuitem');
    var ContentBox = require('component/extension/content-box');
    var KeyCode = require('node').Event.KeyCode;
    var MENU_DELAY = 0.15;
    function afterHighlightedChange(e) {
        var target = e.target, self = this;    // hover 子菜单,保持该菜单项高亮
        // hover 子菜单,保持该菜单项高亮
        if (target !== self && target.isMenuItem && e.newVal) {
            self.clearHidePopupMenuTimers();
            if (!self.get('highlighted')) {
                self.set('highlighted', true);    // refresh highlightedItem of parent menu
                // refresh highlightedItem of parent menu
                target.set('highlighted', false);
                target.set('highlighted', true);
            }
        }
    }    /**
 * Class representing a submenu that can be added as an item to other menus.
 * xclass: 'submenu'.
github kissyteam / kissy / src / menu / src / menu / submenu.js View on Github external
/**
 * @ignore
 * submenu control for kissy, transfer item's keyCode to menu
 * @author yiminghe@gmail.com
 */

var util = require('util');
var SubMenuTpl = require('./submenu-xtpl');
var MenuItem = require('./menuitem');
var ContentBox = require('component/extension/content-box');
var KeyCode = require('node').Event.KeyCode;
var MENU_DELAY = 0.15;

function afterHighlightedChange(e) {
    var target = e.target,
        self = this;
    // hover 子菜单,保持该菜单项高亮
    if (target !== self && target.isMenuItem && e.newVal) {
        self.clearHidePopupMenuTimers();
        if (!self.get('highlighted')) {
            self.set('highlighted', true);
            // refresh highlightedItem of parent menu
            target.set('highlighted', false);
            target.set('highlighted', true);
        }
    }
}
github jsreport / jsreport-core / lib / extensions / extensionsManager.js View on Github external
async _useOne (extension) {
      try {
        extension.options = extend(
          true,
          {},
          extension.options || {},
          extension.name != null ? reporter.options.extensions[camelCase(extension.name)] : {},
          extension.name != null ? reporter.options.extensions[extension.name] : {}
        )

        // we need to check for string "false" to support disabling extension by env or CLI args
        // since this option does not coerce by schema validation at this point but later
        if (extension.options.enabled === 'false' || extension.options.enabled === '0') {
          extension.options.enabled = false
        }

        if (extension.options.enabled === false) {
          if (!extension.name) {
            reporter.logger.debug(`Anonymous Extension${extension.directory != null ? ` at ${extension.directory}` : ''} is disabled, skipping`)
github jsreport / jsreport-core / lib / reporter.js View on Github external
nfn.file({file: path.join(rootDirectory, 'jsreport.config.json')})

          if (nfn.get('rootDirectory') != null) {
            rootDirectory = nfn.get('rootDirectory')
          }

          if (nfn.get('mode') != null) {
            mode = nfn.get('mode')
          }
        }
      }
    }

    // we pass a copy of defaults to avoid loosing the original
    // object values
    nfn.defaults({ store: extend(true, {}, this.defaults) })

    this.options = nconfInstance.get()
    this.options.rootDirectory = rootDirectory
    this.options.mode = mode
  }