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

orator

v5.0.0

Published

Unopinionated API http server abstraction - REST or IPC

Downloads

1,125

Readme

Orator

Orator API Server, meant to interact well with Fable, Meadow and FoxHound.

Coverage Status Build Status Dependency Status devDependency Status

This is not an attempt to reinvent the wheel. Nor do we want to make a car with five of them.

Orator is a wrapper for restify, which is an amazing API server. With Orator, you can spin up a web server in a single simple line. And config settings are managed via a consistent json format, so as you begin to have 10 or 15 or 5,000 microservices, you don't have a bunch of boilerplate API server code laying around.

Creating a Simple Server

Okay, so you want to make a simple api server. You would need to create a node.js project, then install the Orator dependency with npm:

npm install orator --save

Then within your javascript code, you could write the following:

// Load the orator module with a few settings
var libOrator = require('orator').new(
	{
		Product: 'MyMicroserviceHash',
		ProductVersion: '9.8.7',

		"APIServerPort": 8000
	});

// Add an API endpoint
libOrator.webServer.post
(
	'/echo/:name',
	function(pRequest, pResponse, fNext)
	{
		// Send back whatever was sent as "name" in the URI
		pResponse.send(pRequest.params);
		return fNext();
	}
);

// Start the web service
libOrator.startWebServer();

After writing this code, you could run your service and a browser going to http://localhost:8000/echo/Gargamel would return a JSON object with Gargamel as the name.

Of course, this is not much different from the Restify code. Where it gets interesting is dealing with things like logging and configuration management. For instance, if you do

// Load the orator module with a few settings
var libOrator = require('orator').new(
	{
		Product: 'MyMicroserviceHash',
		ProductVersion: '9.8.7',

		"APIServerPort": 8000,

		ConfigFile:__dirname+'/MyMicroservice-Config.json'
	});

// Add an API endpoint
libOrator.webServer.post
(
	'/echo/:name',
	function(pRequest, pResponse, fNext)
	{
		// Send back whatever was sent as "name" in the URI
		pResponse.send(pRequest.params);
		return fNext();
	}
);

// Start the web service
libOrator.startWebServer();

Then you could create a file in the same folder as this script called MyMicroservice-Config.json and as long as it is valid json, settings can be loaded from there. Something like this:

{
	"APIServerPort": 8080,

	"UUID":
		{
			"DataCenter": 0,
			"Worker": 0
		},

	"LogStreams":
		[
			{
				"level": "info",
				"path": "./MyMicroService-Server.log"
			},
			{
				"level": "trace",
				"streamtype": "process.stdout"
			}
		]
}

And suddenly the bunyan logging will write to a file and stdout, and you can configure 20 Docker instances to each have a different Worker ID.