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

socket2me-client

v1.2.0

Published

Client for socket2me

Downloads

1

Readme

Socket2me-client

This is a Node JS Client for the Socket2Me Server.

Installation

The Socket2me-client can be installed via NPM.

npm install socket2me-client --save

Example App

Be sure to review the example folder of this repository for more details on setting this up.

var Socket2meClient = require('socket2me-client');
var socket2me = new Socket2meClient('https://mysocketserver.com');

socket2me.on('connected', function(url) {
  console.log('socket server url: %s', url);
});

socket2me.requestHandler(function(request, respond) {
  console.dir(request);
  respond(200,'Hello World!');
}

Function Reference

Request Object

The request object contains the following keys:

  • headers:object - This is an object that contains the header values of the inbound request.
  • method:string - This is the method that the inbound request used.
  • url:string - This is the portion of the Socket2Me Server URL that follows the token. For example if the url was called at http://mysocketserver.com/go/[token]/help/me?fname=bob&lname=smith, this will be '/help/me'
  • query:object - This is an object that includes and URL Query string assignments. For example if the url was called at http://mysocketserver.com/go/[token]/help/me?fname=bob&lname=smith, this will be { "fname": "bob", "lname": "smith" }
  • body - This is the content of the body. If JSON or a URL Encoded Body was detected, this will be an object.

Socket2me#requestHandler(request:obj, respond:fn([status], [body], [headers]){});

Defines a function that is called when a request is received.

  • request:object - See Request Object above
  • respond:function - This is a callback like function that can be used to respond to the request. It is important to note that you must call this within 5 seconds of receiving the request for it to be valid. Otherwise, the Socket2Me Server will respond with a simple 200/OK. This is not to be confused with the response object. This function has 3 arguments it will accept and all are optional.
    • status:number - Specify the status code used in the response to the request. Defaults to 200 if not specified
    • body - Specify the contents of the body in the response to the request. Defaults to 'OK' if not specified
    • headers:object - Specify any additional headers to supply in the response to the request. Defaults to {} if not specified

Example 1

socket2me.requestHandler(function(request, respond) {
  if(request.query.name === 'bob') {
    respond(200, 'Hello Bob!');
  } else {
    respond(400, request.query.name + ' not found!')
  }
});

Example 2

socket2me.requestHandler(function(request, respond) {
  if(request.method === 'POST') {
    console.log(request.query);
    respond();
  }
});

Events

  • connected - Emitted when client has connected with server. Provides parameter url which is the URL that the server generated.
  • disconnected - Emitted when the client is disconnected from the server.

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/.