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

micrun

v1.0.1

Published

Fastly develop micro services

Downloads

7

Readme

micrun

Fastly develop micro services in node.js

Build Status

Features

  • build in consul support for KV store and health check
  • configuration can be stored in consul or locally

Install

npm install micrun

Usage

Example usage without Consul

const micrun = require('micrun');

micrun.createServer({
    port: 9000,
    ip: '127.0.0.1',
    useConsul: false,

    postInterfacesDir: '<path to directory>',
    api_key: 'secret',

    getInterfacesDir: '<path to directory>'
});

Example usage with Consul as a configuration store.

const micrun = require('micrun');

micrun.createServer({
    useConsul: true,
    consulNamespace: 'my-super-app'
});

Available options:

|name |description |required | |---- |------------------------------------- |-------- | |port |Port on which service will be running | yes | |ip |IP of service | yes | |useConsul |if true Consul will be used as configuration store | no | |consulNamespace |Name of directory in Consul KV store | yes if using consul | |consulConfig |Optional configuration for consul (details) | no | |postInterfacesDir |Path to directory where methods are stored | no | |api_key |API key for post methods | yes if using post methods | |getInterfacesDir |Path to directory where methods are stored | no |

Creating endpoints

All methods are grouped in interfaces, eg. there can be getSingleUser method in users interface. It could be exposed by service over HTTP GET or POST method.

Creating POST endpoints

  1. Create directory in your project, eg. my-post-endpoints
  2. In configuration of micrun pass absolute path to my-post-endpoints as postInterfacesDir. For POST methods api_key is also required.
  3. To create new interface create directory inside my-post-endpoints. Name of that directory will be also name of interface.
  4. Inside interface directory create .js file for every method. Name of the file must include word Method.

For example getSingleUser method in users interface will have file structure:

my-post-interfaces
├── users
│   ├── getSingleUserMethod.js

getSingleUserMethod.js must export object as below:

const configStore = require('micrun').config;
const config = configStore.getConfig(); // getConfig() can be used to retrieve configuration

module.exports = {
    name: 'getSingleUser', // This is the name of method used in service
    method: function(params) { // This function must return Promise. Params are passed in POST body
        return new Promise((resolve, reject) => {
            // Do something and resolve promise

            return resolve();
        });
    }
};

Using POST endpoint

Make a POST request to http://<ip>:<port> With JSON body:

{
    "API_KEY": "<api_key>",
    "interface": "<interface>",
    "method": "<method>",
    "additional_data": "some_data"
}

Creating GET endpoints

Creating GET methods is similar to creating POST methods. In configuration of micrun pass absolute path to directory with GET interfaces as getInterfacesDir.

getSingleUserMethod.js as a GET method:

module.exports = {
    name: 'get_single_user', // This is the name of method used in service
    method: function(req, res) { 
        return res.json({
            // some data
        });
    }
};

Using GET endpoint

To call GET method simply make request to: `http://:/:interface/:method

Eg. http://127.0.0.1:9000/users/get_single_user

Example

Example project using micrun.

Testing

npm run test