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

wss

v3.3.4

Published

wrapper built upon ws module that provides standard server api only.

Downloads

4,610

Readme

wss

travis dependencies linter coverage node version license

wrapper built upon ws module that provides standard server api only.

usage with server creation

const {createServer} = require('wss')

createServer(function connectionListener (ws) {
  ws.send('welcome!')
  ws.on('message', (data) => {
    ws.send(data.toString()) // echo-server
  })
})
.listen(8080, function () {
  const {address, port} = this.address() // this is the http[s].Server
  console.log('listening on http://%s:%d (%s)', /::/.test(address) ? '0.0.0.0' : address, port)
})

usage with existent server

const {createServer} = require('http')
const {createServerFrom} = require('wss')

const http = createServer()
createServerFrom(http, function connectionListener (ws) {
  ws.send('welcome!')
  ws.on('message', (data) => {
    ws.send(data.toString()) // echo-server
  })
})
http.listen(8080)

wss

the ws.Server object is inherited from ws

wss.prototype.close([callback])

stops the server from accepting new connections.

wss.prototype.listen(handle[, callback])

the handle object can be set to either a server or socket (anything with an underlying handle member), or a {fd} object. This function is asynchronous. callback will be added as a listener for the listening event.

wss.prototype.listen(path[, callback])

start a unix socket server listening for connections on the given path. this function is asynchronous. callback will be added as a listener for the listening event.

wss.prototype.listen([port[, hostname[, backlog[, callback]]]])

begin accepting connections on the specified port and hostname. if the hostname is omitted, the server will accept connections on any ipv6 address (::) when ipv6 is available, or any ipv4 address (0.0.0.0) otherwise. omit the port argument, or use a port value of 0, to have the operating system assign a random port, which can be retrieved by using server.address().port after the listening event has been emitted.

to listen to a unix socket, supply a filename instead of port and hostname.

backlog is the maximum length of the queue of pending connections. The actual length will be determined by your OS through sysctl settings such as tcp_max_syn_backlog and somaxconn on linux. The default value of this parameter is 511. This function is asynchronous. callback will be added as a listener for the listening event.

Note: The server.listen() method may be called multiple times. Each subsequent call will re-open the server using the provided options.

wss.createServerFrom(server=http.Server|https.Server)

returns a new ws.Server based on given web server object. throws if no server is given.

wss.createServer([options[, connectionListener]])

returns a new ws.Server based on given options and connectionListener. underlaying https server is created when tls options have been provided as oftls.createServer(), otherwise it will fallback to a http implementation. the connectionListener is a function which is automatically added to the connection event.