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

@akilio/app-kit

v1.0.7

Published

Resource loader for API based applications

Downloads

3

Readme

app-kit

Application resource loader library

Main features:

  • load application modules by named configuration
  • split modules to service -> api -> env architecture
  • service accept requests and call api
  • api is business logic only
  • env used in api for doing what you need
  • pluggable architecture

Installation

  1. We recommend using yarn insted of npm.
yarn add @akilio/app-kit
  1. Create index.js file with next content:
require('@akilio/app-kit').autostart();
  1. Add this to your package.json scripts section:
"scripts": {
    "start": "node index.js",
    "cli": "node index.js --cli",
  },
  1. Create api/index.js file with exported functions^
function example(env, message) {
	console.log(`Your message is "${message}"`);
}
module.exports = {
	example
};
  1. Create config/index.js file with content:
module.exports = {
	service: {
		cli: {}
	},
	env: {},
	api: {
		example: { cli: {}}
	}
};

Your are ready to run! Call function with next command:

yarn cli example "Hello!"

Building blocks

Service

This type of modules needed for interacting with external services, accept requests, keep connections and etc. For example this can be http-server, database or queue connection manager.

Service modules placed in service directory of your app or can be installed as npm module with names started with app-kit-service-.

Base service module (service/service_test.js) looked like this:

/**
 * Service bootloader function
 * @param  {[type]} config configuration options for your service from configs
 * @param  {[type]} api    list of available api with configs for this service
 * @param  {[type]} call   callback for calling api
 * @return {[type]}        Object
 */
module.exports = async function (config, api, call) {
	// do initialization here...
	for (let apiName in api) { // for example call given apis periodicaly
		setInterval(() => call(apiName, ...api[apiName].args), api[apiName].interval);
	}

	return {
		state: {}, // any state variables associated with service (for monitoring only)
		env: {}, // functions available to call from api by env.<service name>.<function name>
		startup: () => {}, //hook, called when application loaded and ready to start
		shutdown: () => {} //hook, called before application exit
	};
};

Env

This is needed for excluding from api code worked with external enviroinment. For example FileSystem, web-service api, mailing, image conversion and etc.

Env modules placed in env directory of your app or can be installed as npm module with names started with app-kit-env-.

Base env module (env/env_test.js) looked like this:

/**
 * Env bootloader function
 * @param  {[type]} config configuration options for your module from configs
 * @return {[type]}        Object
 */
module.exports = async function (config) {
	// do initialization here...

	return {
		test: () => {} // any function for your api
	};
};

Api

This is your business logic only code, do not place this anything like remote service calls, data transformations and other staff. Keep it clean and you will get highly reusable code.

API modules placed in api directory of your app or can be installed as npm module with names started with app-kit-api-.

Base env module looked like this:

module.exports = { // you need to export some functions
	/**
	 * Example API function
	 * @param  {[type]}    env   loaded and configured env modules
	 * @param  {...[type]} other any arguments you want
	 * @return {[type]}          anything
	 */
	example: function (env, ...other) {} // sync or async function,
	exampleAsync: async function (env, a, b) {
		env.env_test.test();
		env.cli.log(`exampleAsync called with ${a} and ${b}`);
		return a + b;
	}
};

Config

With config you can control which modules loaded and config for them.

You have 3 sections in config file: service, env, api.

Example config:

module.exports = {
	service: {
		service_test: {
			configVar1: "<anything>"
		}
	},
	env: {
		env_test: {
			configVar2: "<anything>"
		}
	},
	api: {
		// functions exported from "api/index.js" file
		example: {
			cli: {} //available for service cli
		},
		exampleAsync: {
			cli: {},
			service_test: { //available for service "service_test"
				interval: 3000,
				args: [1,2]
			}
		},
		other_module: {
			// functions from "api/other_module.js" file
			other_function: {} //available only for another api functions
		}
	}
};

You can rename loaded modules, for example in index.js config you have this:

module.exports = {
	service: {
		"db:mongodb": {}
	}
};

And in local.js config thix:

module.exports = {
	service: {
		"db:tingo": {}
	}
};

In api function code you will call function as env.db.find(...), but when you start with yarn start your code will work with mongodb, but when you start with yarn start local you will work with tingodb fs database.