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

trails-service

v2.0.0

Published

Trails Service Class

Downloads

392

Readme

trails-service

Gitter NPM version Build status Dependency Status Code Climate Follow @trailsjs on Twitter

Note: This module is deprecated in Trails v2. It will be merged into trailsjs/trails in v3.

Trails Service Class. Exposes Trails Application resources to the class instances. Services should extend this Class. This module is installed by default in new Trails applications.

Usage

const Service = require('trails-service')

class MyService extends Service {
  serviceMethod () {
    this.log.info('hello')
    // ...
  }
}

Patterns

Important Note

The specification below is not yet implemented in Trails 1.0. Implementation is tentatively scheduled for 2.x series release.

Overview

In Trails, Controller methods should remain lightweight. Their primary function is to extract the necessary data from the request, and pass the data into a Service method to perform any necessary work. Controller methods also handle any errors received from the Services, and translate them for the client response.

The work performed by the Services can vary, and depending on the kinds of tasks performed by the Service methods, the following patterns can be used to optimize and scale your application.

Traditional Single-Process

Description

By default, Services are instantiated in the same process as the Trails Application. Controllers invoke Service methods directly. The Service Interface directly passes through method calls and arguments to the Service Layer. The scalability of the Service Layer and the Application Layer are coupled together, one-to-one.

For example, Sails Services use this Traditional Single-Process pattern.

Diagram

Applicability

This pattern is applicable for web applications under low/normal load, where the service methods mainly are performing async I/O, such as performing database queries. Should not be used for memory-bound tasks or CPU-intensive tasks such as video encoding, PDF generation, etc.

Multi-Process

Description

Within a single machine or server, multiple Service processes are spawned from the main Application. The Service Interface invokes the Service methods via IPC (Inter-process Communication). The Service Layer returns the response also via IPC, and the Service Interface resolves the caller's Promise.

Diagram

Applicability

Use this pattern to offload CPU-bound work from the main process. Useful for Services that perform short-lived but CPU-intensive tasks such as cryptographically-strong random number generation, or data transformations on small/medium-sized datasets. Should not be used for memory-bound tasks.

Multi-Node Worker Queue

Description

Diagram

Applicability

License

MIT