npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

atomics-http

v3.2.8

Published

atomics-http is a Node.js extension that provides synchronous http calls.

Downloads

32

Readme

atomics-http

atomics-http is a Node.js extension that provides synchronous http or https calls. Minimal dependency and very fast. Worker and Atomics based.

Changes

  • 2022-04-07 Typescript optimized
  • 2022-04-07 Transfer data bug fixed
  • 2022-04-07 File upload support added
  • 2022-04-07 Example available on github
  • 2022-03-15 readTimeout property added
  • 2022-03-14 Added write function for POST requests
  • 2022-03-11 Added support for Functions (using eval)
  • 2022-03-11 Bugfixes
  • 2022-03-10 Option autoClose Worker can also be a number. In this case it means that the worker will be closed if no more requests have been sent after "n" milliseconds.

  • Added Agent support (RC1) for:
    • proxy-agent: https://www.npmjs.com/package/proxy-agent
    • http-proxy-agent: https://www.npmjs.com/package/http-proxy-agent
    • https-proxy-agent: https://www.npmjs.com/package/https-proxy-agent
    • http-cache-agent: https://www.npmjs.com/package/http-cache-agent
    • Buildin http and https Agent: https://nodejs.org/api/http.html#new-agentoptions

Installation

npm install atomics-http

Using

Default http compatibility

const {https} = require('atomics-http');
// OR 
// const {http} = require('atomics-http');
 
var request = https.request({
    method: 'GET',
    headers: {},
    protocol: 'https:',
    host: '127.0.0.1',
    port: 80,
    path: '/'
});

request.setTimeout(10000);
try {
	var result = request.end();
	console.info(result.body.toString());
	console.info(result.response);
} catch (e) {
	console.error(e);
}

Default http compatibility 2

const {https} = require('atomics-http');
// OR 
// const {http} = require('atomics-http');

var request = https.request('https://example.com/');

request.setTimeout(10000);

try {
	var result = request.end();
	console.info(result.body.toString());
	console.info(result.response);
} catch (e) {
	console.error(e);
}

Autoclose worker (6 times slower!)

const {https} = require('atomics-http');
// OR 
// const {http} = require('atomics-http');

var request = https.request('https://example.com/', {autoCloseWorker: true});

request.setTimeout(10000);

try {
	var result = request.end();
	console.info(result.body.toString());
	console.info(result.response);
	// Close worker manualy request.closeWorker();
} catch (e) {
	console.error(e);
}

Autoclose worker by inactivity (best way!)

const {https} = require('atomics-http');
// OR 
// const {http} = require('atomics-http');

var time = 10000; // 10 Seconds 
var request = https.request('https://example.com/', {autoCloseWorker: time});

try {
	var result = request.end();
	console.info(result.body.toString());
	console.info(result.response);
	// Close worker manualy request.closeWorker();
} catch (e) {
	console.error(e);
}

POST Request

const {https} = require('atomics-http');
// OR 
// const {http} = require('atomics-http');

var params = new URLSearchParams({
	'tset1' : 'test%*&',
	'test2': true,
	'test3': 123
})
var post_data = params.toString();

var req = https.request({
	url: 'https://example.com/example.php',
	method: 'POST',
	headers: {
		'Content-Type': 'application/x-www-form-urlencoded',
		'Content-Length': Buffer.byteLength(post_data)
	}
});
req.write(post_data);
var result = req.end();
console.info(result.body.toString());
console.info(result.response);

Fileupload

const {https} = require('atomics-http');
// OR 
// const {http} = require('atomics-http');

var {FormDataStream} = require('form-data-stream');

var postData = new FormDataStream();
postData.set('test', 'abc');
postData.setFile('file1', './dummy.txt');

var options = {
	method: 'POST',
	headers: postData.headers()
};

let url = 'https://example.com/upload.php';
var req = https.request(url, options);

postData.pipeSync(req);

var result = req.end();
console.info(result.body.toString());
//console.info(result.response);

Download file

const ahttp = require('atomics-http').http;
// OR 
// const ahttps = require('atomics-http').https;

var request = httpSync.request('https://example.com/file.txt');

const file = fs.createWriteStream("file.txt");
request.pipe(file);
// OR request.pipe("file.txt");

try {
	var result = request.end();
	// Body will be null
	// console.info(result.body);
    // Response data:
	console.info(result.response);
} catch (e) {
	console.error(e);
}

All examples

ExtraOptions

  • autoCloseWorker => bool (false = no close, true = close after end) or int (milliseconds)
  • readTimeout => int milliseconds for reading data

Methods of ClientRequest

  • write
  • end
  • pipe
  • setTimeout
  • closeWorker

Benchmark 100 Requests

| Method | Time | |-----------------|---------| | async | 3637 | | sync | 2720 | | sync_autoclose | 13243 |

At the moment not supports Functions in options