{"id":19020242,"url":"https://github.com/trailsjs/trails-service","last_synced_at":"2026-04-28T07:30:19.824Z","repository":{"id":57378874,"uuid":"49358358","full_name":"trailsjs/trails-service","owner":"trailsjs","description":":globe_with_meridians: Trails Service","archived":false,"fork":false,"pushed_at":"2016-12-22T01:42:16.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-04-25T04:21:31.809Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trailsjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-10T07:53:16.000Z","updated_at":"2016-10-31T20:09:13.000Z","dependencies_parsed_at":"2022-09-02T21:21:05.662Z","dependency_job_id":null,"html_url":"https://github.com/trailsjs/trails-service","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailsjs%2Ftrails-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailsjs%2Ftrails-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailsjs%2Ftrails-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailsjs%2Ftrails-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trailsjs","download_url":"https://codeload.github.com/trailsjs/trails-service/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240064610,"owners_count":19742347,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T20:16:16.498Z","updated_at":"2026-04-28T07:30:19.378Z","avatar_url":"https://github.com/trailsjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# trails-service\n\n[![Gitter][gitter-image]][gitter-url]\n[![NPM version][npm-image]][npm-url]\n[![Build status][ci-image]][ci-url]\n[![Dependency Status][daviddm-image]][daviddm-url]\n[![Code Climate][codeclimate-image]][codeclimate-url]\n[![Follow @trailsjs on Twitter][twitter-image]][twitter-url]\n\n### Note: This module is deprecated in Trails v2. It will be merged into [trailsjs/trails](https://github.com/trailsjs/trails) in v3.\n\nTrails Service Class. Exposes Trails Application resources to the class\ninstances. Services should extend this Class. This module is installed\nby default in new Trails applications.\n\n## Usage\n\n```js\nconst Service = require('trails-service')\n\nclass MyService extends Service {\n  serviceMethod () {\n    this.log.info('hello')\n    // ...\n  }\n}\n```\n\n## Patterns\n\n#### Important Note\nThe specification below is not yet implemented in Trails 1.0. Implementation is tentatively scheduled for 2.x series release.\n\n#### Overview\n\nIn 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.\n\nThe work performed by the Services can vary, and depending on the kinds of tasks performed by the Service methods,\nthe following patterns can be used to optimize and scale your application.\n\n### Traditional Single-Process\n\n#### Description\n\nBy default, Services are instantiated in the same process as the Trails Application. Controllers\ninvoke Service methods directly. The **Service Interface** directly passes through method\ncalls and arguments to the **Service Layer**. The scalability of the **Service Layer** and the **Application Layer**\nare coupled together, one-to-one.\n\nFor example, [Sails Services](http://sailsjs.org/documentation/concepts/services) use this Traditional Single-Process\npattern.\n\n#### Diagram\n\u003cimg src=\"http://trailsjs.io/images/trails-service-traditional.png\"\u003e\n\n#### Applicability\nThis pattern is applicable for web applications under low/normal load, where the service methods mainly\nare performing async I/O, such as performing database queries. Should not be used for memory-bound \ntasks or CPU-intensive tasks such as video encoding, PDF generation, etc.\n\n### Multi-Process\n\n#### Description\nWithin a single machine or server, multiple Service processes are spawned from the main Application.\nThe **Service Interface** invokes the Service methods via IPC (Inter-process Communication). The **Service Layer**\nreturns the response also via IPC, and the **Service Interface** resolves the caller's `Promise`. \n\n#### Diagram\n\u003cimg src=\"http://trailsjs.io/images/trails-service-child-process.png\"\u003e\n\n#### Applicability\nUse 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.\n\n\n### Multi-Node Worker Queue\n\n#### Description\n\n#### Diagram\n\u003cimg src=\"http://trailsjs.io/images/trails-service-workers.png\"\u003e\n\n#### Applicability\n\n\n\n## License\n[MIT](https://github.com/trailsjs/trails/blob/master/LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/trails.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/trails\n[ci-image]: https://img.shields.io/travis/trailsjs/trails-service/master.svg?style=flat-square\n[ci-url]: https://travis-ci.org/trailsjs/trails-service\n[daviddm-image]: http://img.shields.io/david/trailsjs/trails-service.svg?style=flat-square\n[daviddm-url]: https://david-dm.org/trailsjs/trails-service\n[codeclimate-image]: https://img.shields.io/codeclimate/github/trailsjs/trails-service.svg?style=flat-square\n[codeclimate-url]: https://codeclimate.com/github/trailsjs/trails-service\n[gitter-image]: http://img.shields.io/badge/+%20GITTER-JOIN%20CHAT%20%E2%86%92-1DCE73.svg?style=flat-square\n[gitter-url]: https://gitter.im/trailsjs/trails\n[twitter-image]: https://img.shields.io/twitter/follow/trailsjs.svg?style=social\n[twitter-url]: https://twitter.com/trailsjs\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrailsjs%2Ftrails-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrailsjs%2Ftrails-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrailsjs%2Ftrails-service/lists"}