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

functional-services

v0.0.4

Published

Functional Service Server

Downloads

24

Readme

functional-services Build Status

NodeJS Functional Service RPC Server

Install

  npm install functional-services

Examples:

Initialize (INIT):

var FuncServices = require( "functional-services" );

var keys = {
	'public_key': 'secret_key'
};

var services = {
	'/namespace/action': (req, callback) => {
		callback(null, 'Hello '+req.payload.name);
	}
};

var funcServices = FuncServices(keys, services);

Options:

  • keys: AES Keys
  • services: Domaindriven name and function

Service:

var services = {
	'[ domain ]': (request, callback) => {
		// request
		// {
		// 		url: [ domain ],
		// 		public_id: [ public_key ],
		// 		payload: [ payload ]
		// }

		callback([ error ], [ response ]);
	}
};

Run service.

Note: Need a value or a (global/options) timeOutFunction. If the value is empty, it is loaded from the timeOutFunction.

  • domain Address of the service
  • public_key The public key sent along.
  • payload Payload
  • error Send null if no error.
  • response (optional) Response Payload
var services = {
	'/namespace/action': (req, callback) => {
		callback(null, 'Hello '+req.payload.name);
	}
};

Connect

Client NodeJS

Send request to Server.

// Private / Public Key Storage
var keys = {
	'public_key': 'private_key'
};

// Get Client / Server
funcServices = FuncServices(keys, {});

// HTTP Request Options
var options = { 
	host: 'localhost', 
	path: '/', 
	port: port, 
	method: 'POST' 
};

// Sending Data
var data = {
	public_id: 'public_key',
	// Payload
	ciphered: { 
		url: "/demos/helloworld", // Router Service Address
		public_id: 'public_key',
		payload: {name: 'Peter'} // Payload Params
	}
};

// HTTP Request Callback
var callback = function(response) {
	var str = ''
	response.on('data', function (chunk) {
		str += chunk;
	});
	response.on('end', function () {
		var raw = JSON.parse(str);
		var r = funcServices.decrypt(raw);

		console.log(r);
	});
}

var req = http.request(options, callback);
req.end(JSON.stringify(funcServices.encrypt(data)));

Server ExpressJS

Use ExpressJS

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

var funcServices = FuncServices(keys, services);
var middleware = funcServices.express();

app.use('/api', middleware);
app.listen(3000, function() {});

Server HTTP

// HTTP Server
const requestHandler = (request, response) => {
	// Get Chunks
	var fullBody = '';
	request.on('data', function(chunk) {
		fullBody += chunk.toString();
	});
	// Request finish
	request.on('end', function() {
		// Get JSON
		var body = JSON.parse(fullBody);

		// Decode, Route, Run, Encrypt, Response
		funcServices.router(body, (err, res) => {
			// Send
			response.end(JSON.stringify(res));
		});
	});
}

// Start Server
const server = http.createServer(requestHandler);

server.listen(port, (err) => {
	console.log('Server run.')
});

Contributors

Philipp

The MIT License (MIT)