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

portluck

v0.4.4

Published

A unified HTTP/TCPSocket/WebSocket server for receiving arbitrary data

Downloads

30

Readme

Portluck

Build Status

Accepts arbitrary data on a single port via HTTP, HTTPS, WebSockets, or a TCP socket. Optimally data should be delimited by a \n character to speed up connection detection (read below).

Since we're sniffing for the connection type you will need to send at least 3 bytes over a raw TCP socket in order to trigger a message event. If those 3 bytes happen to match the beginning of a valid HTTP method we additionally wait for \r or \n to determine that it is/isn't an HTTP request.

portluck.Server

new portluck.Server([messageCallback][, options])

Creates a new server that inherits https.Server. If messageCallback is sent, it will be added as a listener for "message" event. See bottom for options.

Event: 'message'

Fired when a client sends a message. Event is sent (message, writer, socket, source). message is a buffer containing the message received. writer is an instance of ResponseWriter and can be used to respond to the message. socket is the source socket that sent the message. You should only read properties off the socket, like remoteAddress and not use the write/end methods. source is either a net.Socket or a http.IncomingMessage.

Event: 'clientConnect'

Fired when a client connects. Event is sent (writer, socket, source). You should only read properties off the socket, like remoteAddress and not use the write/end methods. writer is an instance of ResponseWriter can be used to respond. The writer has write, end, and destroy methods. source is either a net.Socket or a http.IncomingMessage.

Event: 'clientDisconnect'

Fired when a client disconnects. Event is sent socket which is the socket that disconnected.

Event: 'clientError'

Fired when there's an error emitted from a client. Event is sent (error, socket).

server.listen(port [,callback])

Accepts the same parameters and options as http.Server.listen.

ResponseWriter

writer.write(message)

Writes message to the underlying source socket. message can be a string or Buffer. If you plan on responding to messages asynchronously, you should call endAfterWrite since HTTP/HTTPS requests are automatically closed on the next tick (unless you sent explicitEnd option).

writer.endAfterWrite()

If an automatic end() is scheduled to happen next tick, calling doneAfterWrite prevents that from happening and waits to automatically call end() until the next write(). This is not needed if you created the server with the explicitEnd option.

writer.end([message])

Writes message, if passed, to the underlying source socket. If the source was a HTTP/HTTPS request, it is ended and a response is sent. No more writes are allowed on this writer. If the request was already terminated on the client side then message will be silently dropped and not sent.

writer.close()

Closes (by sending a FIN) the underlying source socket. No more writes are allowed on this writer.

writer.destroy()

Immediately closes the underlying source socket. Similar to socket.destroy() No more writes are allowed on this writer.

Options

rawFallback

Boolean for whether we should fallback to a raw socket connetion if http/tls/websocket isn't detected.

timeout

See net.Server.timeout. Defaults to 2 minutes. Note: We wait 1 second to try and wait for bytes to determine what type of connection it is. Your timeout applies AFTER that if no data is sent immediately.

allowOrigin

Origin to respond with Allow-Access-Control-Origin for. Value can be a string or RegExp. String values can contain a single * for wildcard matching [a-zA-Z0-9_-]. Do not add a protocol (like https://). Note: *.example.com is special and matches example.com, www.example.com, and www.staging.example.com. Note 2: A origin ending in :* will allow any ports. So example.com:* would match example.com and example.com:4000.

allowUndefinedOrigin

Automatically allow a request if the origin is undefined. You usually want this to be true since browsers only don't send origin headers for same-domain requests. Defaults to true. If this is false, then the undefined origin will be passed to allowOrigin function/regex.

explicitEnd

If set to true you are required to call writer.end() on every message received. By default, messages are ended on the nextTick after firing 'message' event.

messageLimit

Maximum number of bytes per message. This is also the max size of the buffer when sniffing for connection type. Defaults to 0, which means no limit.

Todo

  • Support UDP sockets as well

By James Hartig