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

@phish108/web-service-core

v1.0.2

Published

Basic Wrapper for Service Endpoints for REST and MQ

Downloads

7

Readme

node-web-service

Synthesize common functions for JS-Koa Webserivces.

Automatic Testing

This package serves as the foundation for the sdg js services. It allows to focus on handler functions instead by removing common code. It also enforces common standard practices for the services.

Features

  • JSON log format (based on winston)
  • Endpoint level performance logging
  • Koa integration
  • Message Queue integration
  • graphql backend integration
  • Dynamic configuration

Usage

npm install @phish108/web-service-core

After that the component can be included in the project.

import * as App from "@phish108/web-service-core"

// load your service's request handlers
import * as ServiceHandler from "./handler"

// load your service's configuration defaults, which should
// include your endpoint definition.
import defaults from "./defaults.json" with {type: "json"};

const instance = await App.init(defaults, ServiceHandler);

// run any module level initialisation based on instance.config etc.

instance.run();

The instance has a single run() function, but includes references to the service's config, Logger, message queue (mq) and graphql database (db). These options can be used to initialise anly components if needed. These components are also available per request in the request's ctx.state object.

Service configuration

This system uses @phish108/yaml-configurator for system configuration. This allows for flexible service configuation in YAML or JSON with default presets.

The defaults need to be provided as JSON (to make us of the JSON importer).

Routes

In order to make this module work for you, you need to define your endpoint logic under endpoints. The following example shows a simple service configuation with a single endpoint.

{
    "endpoints": [
        {
            "route": "/hello",
            "method": "post",
            "handler": [
                "loadFromDatabase",
                "respondHello"
            ]
        }
    ]
}

The handler list needs to be a list of type string, where each string is a handler provided in your ServiceHandler-object. Internally these handlers are stacked by docker compose in the given sequence. If a handler is missing, the service raises an error and refuses to start.

Configuration files

The init() function requires the defaults and the service handler object. Optionally, one can pass a number of locations where the module should look for the configuration files. By default the module will check the following locations in the order given below:

  • /etc/app/config.yaml
  • /etc/app/config.json
  • ./config.yaml
  • ./tools/config.yaml

It is convinient not to touch these locations and just place your config in one of these locations in your Docker container. If you insist, you can pass custom locations to the init() function. These locations will be prepended to the default locations, so in case a sysadmin ignores your locations the default locations will still work.