{"id":15664729,"url":"https://github.com/betula/node-shared","last_synced_at":"2026-03-03T09:32:37.935Z","repository":{"id":55595919,"uuid":"190686149","full_name":"betula/node-shared","owner":"betula","description":"Shared logic for Node.JS","archived":false,"fork":false,"pushed_at":"2021-02-22T14:25:28.000Z","size":368,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-13T02:50:06.889Z","etag":null,"topics":["dependency-injection","dependency-provider","di","modules-architecture","shared","shared-logic"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/betula.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":"2019-06-07T04:07:37.000Z","updated_at":"2022-06-11T15:32:20.000Z","dependencies_parsed_at":"2022-08-15T04:00:40.329Z","dependency_job_id":null,"html_url":"https://github.com/betula/node-shared","commit_stats":null,"previous_names":["betula/node-provide"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/betula/node-shared","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betula%2Fnode-shared","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betula%2Fnode-shared/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betula%2Fnode-shared/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betula%2Fnode-shared/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/betula","download_url":"https://codeload.github.com/betula/node-shared/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betula%2Fnode-shared/sbom","scorecard":{"id":235331,"data":{"date":"2025-08-11","repo":{"name":"github.com/betula/node-shared","commit":"75c19ea2cecb1387d5c473876659cc5e47a0b727"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":0,"reason":"Found 0/26 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/betula/node-shared/build.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/betula/node-shared/build.yml/master?enable=pin","Warn: npmCommand not pinned by hash: .github/workflows/build.yml:25","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/build.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 5 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-17T05:35:17.591Z","repository_id":55595919,"created_at":"2025-08-17T05:35:17.592Z","updated_at":"2025-08-17T05:35:17.592Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30039885,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T06:58:30.252Z","status":"ssl_error","status_checked_at":"2026-03-03T06:58:15.329Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["dependency-injection","dependency-provider","di","modules-architecture","shared","shared-logic"],"created_at":"2024-10-03T13:43:58.816Z","updated_at":"2026-03-03T09:32:37.910Z","avatar_url":"https://github.com/betula.png","language":"TypeScript","readme":"# node-shared\n\n[![npm version](https://img.shields.io/npm/v/node-shared?style=flat-square)](https://www.npmjs.com/package/node-shared) [![npm bundle size](https://img.shields.io/bundlephobia/minzip/node-shared?style=flat-square)](https://bundlephobia.com/result?p=node-shared) [![typescript supported](https://img.shields.io/npm/types/typescript?style=flat-square)](./src/index.ts)\n\nService provider for Node.JS without pain with Dependency Injection Container, dependency registration, and configuration.\n\n- You can use it at any place of your application without rewrite your applications architecture or other preparations or initializations.\n- Each dependency can be class or function.\n- You can override your dependencies for unit testing without hack standard Node.JS require mechanism.\n- You can use TypeScript or JavaScript.\n\n## Examples\n\n```javascript\nimport { shared } from \"node-shared\";\n\n// It is can be service or shared state or cross requests data\nclass Users {\n  async getById(id) {\n    ...\n  }\n}\n\nconst sharedUsers = () =\u003e shared(Users);\n\n// And with express for example\napp.get(\"/user/:id\", async (req, res) =\u003e {\n  const users = sharedUsers();\n  res.json(await users.getById(req.params.id));\n});\n```\n\nAnd\n\n```javascript\nimport { shared } from \"node-shared\";\n// ...\n\nclass Db { /* ... */ }\nclass Server { /* ... */ }\n// ...\n\n// Inject dependencies using a shared function and class properties\nexport default class App {\n  db = shared(Db);\n  server = shared(Server);\n  // ...\n  start() {\n    this.db.init();\n    // ...\n  }\n}\n\n// index.ts\nnew App().start(); // You can create an instance directly as usually class\n```\n\n## Unit testing\n\nYou can use `mock` to provide mocks into your dependencies.\n\n```javascript\nimport { mock } from \"node-shared\";\nimport { Users, Api } from \"./shareds\";\n\ntest(\"Users service should call api service inside\", async () =\u003e {\n  const apiMock = mock(Api, {\n    getUserById: jest.fn();\n  });\n\n  const users = new Users();\n\n  await users.getById(\"John\");\n  expect(apiMock.getUserById).toHaveBeenCalledWith(\"John\");\n});\n```\n\nIf you use Jest for unit testing you need to add some code to your `jest.config.json` file.\n\n```javascript\n// jest.config.json\n{\n  ...\n  setupFilesAfterEnv: [\n    \"node-shared/jest\"\n  ],\n  ...\n}\n```\n\nThis code means that after each test cached shareds instances will be clear. For another testing frameworks, you need call `free` after each test case manually for cleanup cached instances of dependencies.\n\n```javascript\nafterEach(require(\"node-shared\").free);\n```\n\n## API Reference\n\n**shared**\n\nReturns instance of your dependency. Each dependency can be class or function.\n- For class. The class will be instantiated once and cached\n- For function. The function will be called and result cached\n\n```javascript\nconst db = shared(Db);\n```\n\n**mock**\n\nDefine resolved value for any dependency.\n\n```javascript\nconst mockedDb = mock(Db, {\n  connect: jest.fn()\n});\n\nshared(Db).connect();\nexpect(mockedDb.connect).toHaveBeenCalled();\n```\n\n**free**\n\nClean all cached shared instances. It's needed for testing usually. Has no parameters.\n\n```javascript\nfree()\n```\n\n## Install\n\n```sh\nnpm i node-shared\n```\n\nEnjoy and Happy Coding!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbetula%2Fnode-shared","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbetula%2Fnode-shared","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbetula%2Fnode-shared/lists"}