How to use phin - 10 common examples

To help you get started, we’ve selected a few phin 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 remoteintech / remote-jobs / bin / build-site.js View on Github external
async function request( url ) {
	console.log(
		'Requesting URL "%s"',
		url.length > 70
			? url.substring( 0, 67 ) + '...'
			: url
	);
	const res = await phin.promisified( url );
	if ( res.statusCode !== 200 ) {
		throw new Error(
			'HTTP response code ' + res.statusCode
			+ ' for URL: ' + url
		);
	}
	return res.body.toString();
}
github electerm / electerm / npm / install.js View on Github external
function getVer () {
  return rp({
    url: versionUrl,
    timeout: 15000
  })
    .then(res => res.body.toString())
}
github ethanent / Vaxic / lib / route / route.js View on Github external
res['route'] = async (opts) => {
		if (!opts) throw new Error('Missing opts property.')
		if (!opts.hasOwnProperty('origin') && !opts.hasOwnProperty('url')) throw new Error('Missing origin or url property for route options.')

		let newHeaders = req.headers

		if (newHeaders.hasOwnProperty('host')) newHeaders.host = url.parse(opts.origin).host

		try {
			let forwardRes = await p(Object.assign({
				'method': req.method,
				'headers': newHeaders,
				'url': new url.URL(req.url.pathname, opts.origin).toString()
			}, req.body ? {
				'data': req.body
			} : {}, opts, {
				'stream': true
			}))

			res.writeHead(forwardRes.statusCode, forwardRes.headers)
			forwardRes.stream.on('data', (chunk) => res.write(chunk))
			forwardRes.stream.on('end', () => res.end())
		}
		catch (err) {
			throw err
		}
github electerm / electerm / app / app.js View on Github external
async function waitUntilServerStart (url) {
  let serverStarted = false
  while (!serverStarted) {
    await rp({
      url,
      timeout: 100
    })
      .then(() => {
        serverStarted = true
      })
      .catch(() => null)
  }
}
github electerm / electerm / npm / install.js View on Github external
function getReleaseInfo (filter) {
  return rp({
    url: releaseInfoUrl,
    timeout: 15000
  })
    .then((res) => {
      return JSON.parse(res.body.toString())
        .release
        .assets
        .filter(filter)[0]
    })
}
github zKillboard / evewho / cron / update_characters_by_affiliation.js View on Github external
module.exports = f;

var phin = require('phin').defaults({'headers': { 'User-Agent': 'evewho.com' } });

async function f(app) {
    let promises = [];

    let chars = await app.mysql.query('select character_id, corporation_id, alliance_id, faction_id from ew_characters where lastUpdated > 0 and lastAffUpdated < date_sub(now(), interval 1 day) order by lastAffUpdated limit 1000');
    if (chars.length == 0) return;

    let char_array = [];
    let map = {};
    for (let i =0; i < chars.length; i++) {
        char_array.push(chars[i].character_id);
        map[chars[i].character_id] = chars[i];
    }
    await app.mysql.query('update ew_characters set lastAffUpdated = now() where character_id in (' + char_array.join() + ')');

    let url = 'https://esi.evetech.net/v1/characters/affiliation/'
github MihaiVoinea / makerlog-cli / build / commands / done.js View on Github external
},{"../package.json":"../package.json"}],"../config/phin.config.js":[function(require,module,exports) {
const p = require("phin");

const store = require("./store.config");

let options = {
  parse: "json",
  core: {
    headers: {
      "Content-Type": "application/json"
    }
  }
};
if (store.has("token")) options.core.headers.Authorization = "Token " + store.get("token");
module.exports = p.defaults(options);
},{"./store.config":"../config/store.config.js"}],"../components/loader.js":[function(require,module,exports) {
"use strict";
github zKillboard / evewho / bin / cron.js View on Github external
#!/usr/bin/env node

var Database = require('../classes/Database.js');
var getJSON = require('get-json');
var redis = require('async-redis').createClient();
var phin = require('phin').defaults({'method': 'get', 'headers': { 'User-Agent': 'evewho.com' } });

const app = {};

app.debug = false;
app.bailout = false;
app.error_count = 0;
app.phin = phin;
app.fetch = async function(url, parser, failure, options) {
    try {
        return await parser(app, await phin(url), options);
    } catch (e) {
        return failure(app, e);
    }
};
app.redis = redis;
app.mysql = new Database({
github MihaiVoinea / makerlog-cli / build / commands / login.js View on Github external
},{"../package.json":"../package.json"}],"../config/phin.config.js":[function(require,module,exports) {
const p = require("phin");

const store = require("./store.config");

let options = {
  parse: "json",
  core: {
    headers: {
      "Content-Type": "application/json"
    }
  }
};
if (store.has("token")) options.core.headers.Authorization = "Token " + store.get("token");
module.exports = p.defaults(options);
},{"./store.config":"../config/store.config.js"}],"../components/loader.js":[function(require,module,exports) {
"use strict";
github MihaiVoinea / makerlog-cli / build / commands / todo.js View on Github external
},{"../package.json":"../package.json"}],"../config/phin.config.js":[function(require,module,exports) {
const p = require("phin");

const store = require("./store.config");

let options = {
  parse: "json",
  core: {
    headers: {
      "Content-Type": "application/json"
    }
  }
};
if (store.has("token")) options.core.headers.Authorization = "Token " + store.get("token");
module.exports = p.defaults(options);
},{"./store.config":"../config/store.config.js"}],"../components/loader.js":[function(require,module,exports) {
"use strict";

phin

The ultra-lightweight Node.js HTTP client

MIT
Latest version published 4 months ago

Package Health Score

74 / 100
Full package analysis

Popular phin functions