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

microservice-bootstrap

v1.0.8

Published

A bootstrap for micro services based on node

Downloads

11

Readme

Micro Service Bootstrap for NodeJS

Microservice Bootstrap as a commandline tool (alternatively, you can also clone from https://github.com/coreorm/node-micro-service-bootstrap and add your own service manually).

It takes all the boring chores away, while leaving the fun part to you: the very service / API you wanted.

Heroku App Example: https://glacial-mountain-78419.herokuapp.com/.

Example APIs:

Quick start

Install from NPM

First, install the command

npm install -g microservice-bootstrap

Then create your web service by running

microservice-bootstrap create -t path-to-myservice

Then wait patiently, it will install the service and all dependencies (Yes, you don't need to run npm install').

Create your own service.

Simply run

microservice-bootstrap add-service my-service

If you want to add more than one, just separate the names with comma (,).

microservice-bootstrap add-service service-name1,service-name2...

By default, it will expose GET /my-service api.

For more details, run microservice-bootstrap add-service -h.

Start the server

microservice-bootstrap run [options]

e.g.

microservice-bootstrap run -e local -s my-service -v

Or run microservice-bootstrap run -h to see the man page for more details on the allowed options.

How-to

Service How-to

The server is already setup with global APP variable, simply do your routes (APP is an instance of express) e.g.

APP.get('/', function(req, res) {
    res.send('hello world!');
});

If you have added services using the CLI tool, a default GET /[service name] is already added for you.

For more details, check express website.

JSON API response maker.

This bootstrap includes a very easy to use JSON response maker, the output format is:

{
  "data": <Object or string>,
  "message": <String message>,
  "success": <Boolean true|false>,
  "code": <INT 200-500>,
  "size": <INT size of data in bytes>,
  "time": <TIMESTAMP milliseconds>
}

To use it, simple use the two apis:

  • for successful JSON output: _LIB.util.response.success(data, message, code)
  • for erroneous JSON output: _LIB.util.response.error(error, code).

Details see ./services/default/index.js.

Environment How-to

Configuration

Configurations are environment specific, the are located inside ./config folder, the structure is as follows:

config
├── local
│   ├── app.js
│   └── lib.js
├── production
│   ├── app.js
│   └── lib.js
└── uat
    ├── app.js
    └── lib.js

These 3 environments are pre-installed, if you need to add more environment, just follow the same structure. [environment name as folder name]/[config file]

  • app.js is the application config;
  • lib.js is the library registry;

Config inheritance: production -> uat -> local;

Library

Library files should be placed inside ./lib, following the structure:

lib
├── README.md
├── package-name         // package
│   ├── file1.js
│   └── file2.js
├── package-name.js      // package header - use it to include package files

Unit Tests

Simple run npm run test. All tests are under ./tests folder. Follow exampleTest.js to write your own tests.

Appendix

Globals

| name | description | example/comment | |---|---|---| | _CONF | configuration object | _CONF.env | |_PATH_ROOT|root path| require(_PATH_ROOT + 'header.js') | |_PATH_LIB|library path| points to ./lib/ | | _LIB | custom library object | Libraries can be registered in different environments, see Environment How-to for more details | |_log|log function| see below logging section | |_v|verbose output function| see below verbose output section |

Logging

Use _log(section, data, level = INFO|ERROR|SUCCESS|...) to log (this will format it into logstash friendly message structure)

  • section is where your code runs (e.g. 'service:foo', or a filename)
  • data can be a simple string, or a complex javascript object.
  • level: text value for level of the log

Log format is a custom pattern for logstash, feel free to change it by overriding the custom global._log function, or directly update lib/util/log.js.

Default GROK syntax:

\[(?<datetime>.+)\] (?<level>[\w]+) "(?<section>[^"]+)" DATA<(?<data>.+)>$

Verbose output

Simply use _v(section, data) to log out the verbose output. This will remain hidden unless the app is run with -v or --verbose.

Built-in Debug tool

NOTE: only supported when _CONF.debug = true;

  • _dump(name, object) to record objects in the debug information (returned from api)
  • _debug(message) to record debug messages (returned from api)
  • Pass x-debug-enabled=1 in the header or add ?x-debug-enabled=1 in the query string to enable debug output (NOT supported in production mode).