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

mors

v0.2.0

Published

Express inspired mqtt development framework based on mosca for node

Downloads

26

Readme

Mors

NPM Version Build Status Dependencies

Express inspired mqtt development framework based on mosca for node.

var mors = require('mors')
var app = mors()

app.route('*', function (req, res) {
  console.log('received', req.topic, req.payload);
});

app.listen(9191)

Installation

$ npm install mors

Features

  • Full features from mosca
  • Express style usage
  • Usable inside ANY other node.js app
  • Supports node v0.10 ~ 0.12

Application

settings

The following settings will alter how Express behaves:

  • env Environment mode, defaults to process.env.NODE_ENV(NODE_ENV environment variable) or "development"

app.set(name, value)

Assigns setting name to value.

app.get(name)

Get setting name value.

app.enable(name)

Set setting name to true.

app.disable(name)

Set setting name to false.

app.enabled(name)

Check if setting name is enabled.

app.disabled(name)

Check if setting name is disabled.

app.use([path], function)

Use the given middleware function (with optional mount path, defaulting to "*").

var mors = require('mors');
var app= mors();

// simple logger
app.use(function(req, res, next){
  console.log('PUB %s', req.topic);
  next();
});

// respond
app.use(function(req, res, next){
  res.publish(req.topic + '$reply', 'Hello World');
});

app.listen(9191);

app.VERB(path, [callback...], callback)

The app.VERB() methods provide the routing functionality in Express, where VERB is one of the PUB/SUB verbs (such as app.post()). Multiple callbacks may be given; all are treated equally, and behave just like middleware.

app.all(path, [callback...], callback)

This method functions just like the app.VERB() methods, however it matches all PUB/SUB verbs.

app.route(path)

Returns an instance of a single route, which can then be used to handle PUB/SUB verbs with optional middleware. Using app.route() is a recommended approach for avoiding duplicate route names (and thus typo errors).

var app = mors();

app.route('/events')
.all(function(req, res, next) {
  // runs for all PUB/SUB verbs first
  // think of it as route specific middleware!
})
.subscribe(function(req, res, next) {
  // on subscribe
})
.publish(function(req, res, next) {
  // maybe add a new event...
})

app.authorizer

Set authorizer for authenticating and authorizing the clients. The authorizer include three methods:

  • authenticate(client, username, password, callback)
  • authorizePublish(client, topic, payload, callback)
  • authorizeSubscribe(client, topic, callback)

More information: Authentication & Authorization

app.listen()

Bind and listen for mutt clients on the given host and port. This method is identical to mors.Server() witch inherits from mosca.Server.

var mors = require('mors');
var app = mors();
app.listen(9191);

Request

req.params

This property is an object containing properties mapped to the named route "parameters". For example, if you have the route /user/:name, then the "name" property is available to you as req.params.name. This object defaults to {}.

// ROUTE "/user/:name" with TOPIC "/user/ty"
req.params.name
// => "ty"

More information: routes.js

req.route

The currently matched Route containing several properties (such as the route's path string, the params, and so on).

app.get('$user/:id?', function(req, res){
  console.log(req.route);
});

Example output from the previous snippet:

{
	params: {
		id: '1'
	},
	splats: [],
	path: '$user/:id'
}

req.topic

The topic of the request packet.

req.payload

The payload of the request packet.

req.qos

The qos of the request packet.

req.retain

The retain of the request packet.

Response

res.topic

Set response topic.

res.payload

Set response payload

res.qos

Set response qos

res.retain

Set response retain

res.publish([message], [callback])

Publish a response with the message.

res.topic('$foo/bar').publish('hello');
res.topic('$foo/bar').publish('hello', cb);

Router

router.use([path], function)

Use the given middleware function, with optional mount path, defaulting to "*".

Middleware is like a plumbing pipe, requests start at the first middleware you define and work their way "down" the middleware stack processing for each path they match.

router.route(path, callback)

Currently this is treated equally, and behave just like use.

Middleware

Links

License

MIT