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

incoming-message-hash

v5.0.0

Published

Generate a one-way hash from an http.IncomingMessage

Downloads

9,033

Readme

incoming-message-hash

Generate a one-way hash from an http.IncomingMessage

install

$ npm install incoming-message-hash --save

example

This example demonstrates how the hashing function returns a different hash based on the IncomingMessage's method, path, query string, headers and body.

import hash from 'incoming-message-hash'
import { createServer } from 'http'

createServer((req, res) => {
  req.pipe(hash()).pipe(res)
}).listen(4567, () => {
  console.log('Server is listening on port 4567');
})
$ curl http://localhost:4567; echo
e91caf6d7b009b5af0fb2e18cff95598
$ curl http://localhost:4567/foo; echo
2f24d536fd0ca7c4eb72a8d64440066f
$ curl http://localhost:4567/foo?a=b; echo
0bb92c398df54668d9020b835c345cb8
$ curl http://localhost:4567/foo?a=c; echo
02bd995c9ebccfc0332619a03ce0a688
$ curl -H "Host: www.flickr.com" http://localhost:4567; echo
ce8f3e6257911a9499923d0deebe56b5
$ curl -X POST http://localhost:4567; echo
41ba64dca3f3070b361b302a17742973
$ curl -X POST -d "yay" http://localhost:4567; echo
64ae029a6a4add75fadb03811a13caa7

usage

var hash = require('incoming-message-hash');

hash([algorithm='md5'[, encoding='hex']])

Returns a new crypto.Hash stream using the specified algorithm and encoding (defaults to "md5" and "hex"). You can pipe your http.IncomingMessage in and get a hash back.

import hash from 'incoming-message-hash'
import { createServer } from 'http'

createServer((req, res) => {
  req.pipe(hash()).pipe(res)
})

hash.sync(req, body[, algorithm='md5'[, encoding='hex']])

Synchronous version of hash() that accepts an http.IncomingMessage and its body and returns the hash. You must buffer up the request body yourself if you wish to use this method.

import { promise } from 'incoming-message-hash'
import { createServer } from 'http'

createServer(async function (req, res) {
  let body = ''

  req.on('data', chunk => body += String(chunk))

  req.on('end', () => {
    res.end(sync(req, body))
  })
})

hash.promise(req[, algorithm='md5'[, encoding='hex]])

Asynchronous version of hash() that accepts an http.IncomingMessage and buffers the body up for you.

import { promise } from 'incoming-message-hash'
import { createServer } from 'http'

createServer(async (req, res) => {
  res.end(await promise(req))
})

license

This software is free to use under the MIT license. See the LICENSE file for license text and copyright information.