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

dean_http_dev

v1.0.1

Published

Trawling through an onslaught of interviews and an inummerable measure of Hacker Rank tests, I found that I was not only learning a lot, but I was also finding a way to solve problems that I had never thought of.

Downloads

2

Readme

Custom Fetch Implementation

Trawling through an onslaught of interviews and an inummerable measure of Hacker Rank tests, I found that I was not only learning a lot, but I was also finding a way to solve problems that I had never thought of.

During the course of my test taking, I had run into a question twice that had given me issues; writing a custom HTTP implementation. I pride myeself on knowing the basics, yet not once but twice, I had not been able to do just that, create a custom implementation of an http query using the standard node library. This was a great learning experience, and I am proud of it, I will struggle and grow so my failures do not occur more than twice, the second time is a mistake and the third time shows a lack of growth.

Documentation:

What I Learned

The HTTP Package system follows a similar pattern to the Promise system, but with a few key differences. The differences are highlighted in the key fact that the HTTP package is not a promise, but a continuous series of requests that are split up into Chunks (Type of ) that are captured until the stream "ends".

A basic tree model of what I used for the HTTP package is shown below.

HTTP
└── Request
	├── Response (From the request)
	|	└── on
	|		├── data
	|		|	└──"Data is coming in chunks and is being stored in a buffer"
	|		|
	|		└── end
	|			└──"When chunks stop being sent over the stream, the data is assigned to the provided object"
	├── on
	|	└─── error
	|		└── "If there is an error, the error is assigned to the provided object"
	└── end
   		└── "When the request is completes it destroys itself"
Promise
└── Pending
	├── "While the promise is pending, await"
	├── Reject
	|	└── "If the promise is rejected, ƒ(reject) is called"
	└── Fulfill
		└── "If the promise is resolved, ƒ(resolve) is called"

While taking advantage of the Request and Response objects we can combine the logic with a Promise implementation. The Promise implementation is shown below.

Implementation
└── Pending
	├── Response (From the request)
	|	└── on
	|		├── data
	|		|	└── Fulfill
	|		|		└── "Once the stream of chunks stops, the data is passed to the ƒ(resolve)"
	|		|
	|		└─── error
	|			└── Reject
	|				└── "On erroring out, the error is passed to ƒ(rejection)"
	└── end
		└── "When the request is completes it destroys itself"

The Promise implementation is a bit more complex, but it is a lot more flexible and can be used in a variety of different situations, while not being feature compelete (Polyfills for multi-browser support, handling different HTTP verbiage, and handling extreme edge cases), it reaches the minimum viable qualifications for my needs.