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

ears

v0.3.1

Published

messaging framework for communicating with running node.js applications over http

Downloads

17

Readme

Ears

Simple listening plugin for node.js applications. Send messages to your running application in JSON over http.

build status

Installation

$ npm install ears

Usage

Ears is very simple to use. It listens on your port of choice (or auto-detects a free port above 3999) on your address of choice (defaulting to INADDR_ANY) for incoming JSON POST requests. Ears is an EventEmitter, and will emit "message" on every incoming "directive". Your application can then respond to the event in any way it sees fit.

var Ears = require('ears');

ears = new Ears({ port: 3333 });
ears.on('testMessage', function (message) {
	console.log(message); // This is my test message!
});
ears.listen();
$ curl localhost:3333 -H 'content-type: application/json' -d '{ "directive": "testMessage", "message": "This is my test message!" }'
{"ok":true,"message":"ok"}
$

Options

Options are passed on instance creation, i.e. new Ears([options]);

port: [null]: Port to listen on, defaults to first available above 3999

verbose: [true]/false: Talk about listening and incoming requests

messages.ok: Response string on ok valid requests

messages.nok: Response string on invalid requests

If you are using winston in your application, Ears can log to it rather than stdout:

winston.logger: winston

winston.level: 'info'

Methods

listen([options], [callback])

// Just listen
ears.listen();

// Listen with a callback
ears.listen(function () {});

// Listen on a specific address with a callback
ears.listen({
	host: '127.0.0.1' // Defaults to INADDR_ANY (all addresses on host)
}, function () {});

muffs([callback])

// Stop responding to requests, with an optional callback
ears.muffs();
ears.muffs(function () {});

Response Codes

If you...

send a properly formed request with appropriate properties		-> 200 OK
send a GET request												-> 405 Method Not Allowed
send a POST request without application/json content type		-> 400 Bad Request
send a JSON object missing the required properties				-> 400 Bad Request
send malformed JSON												-> 400 Bad Request

What can it do?

I developed this module initially to provide a way to talk to production node.js applications from the command line using cURL. By integrating Ears into applications, I can communicate graceful shutdown commands to node instances as part of deploy scripts, etc.

Since it is not specialized to a particular purpose, it can be used anywhere it would be useful to convey messages or data via JSON to a node.js application from the local host.

Test Coverage

Ears has a full test suite written for mocha. npm install -g mocha for access to the binary.

License

(The MIT License)

Copyright (c) 2011 Carson Christian <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.