{"id":24383416,"url":"https://github.com/firstandthird/hapi-hooks","last_synced_at":"2025-06-23T13:33:51.780Z","repository":{"id":57260915,"uuid":"70963883","full_name":"firstandthird/hapi-hooks","owner":"firstandthird","description":null,"archived":false,"fork":false,"pushed_at":"2017-12-07T18:18:08.000Z","size":148,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-06-18T16:21:04.268Z","etag":null,"topics":["hapi-plugin"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/firstandthird.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-15T03:33:27.000Z","updated_at":"2017-11-27T19:20:46.000Z","dependencies_parsed_at":"2022-08-31T16:12:12.645Z","dependency_job_id":null,"html_url":"https://github.com/firstandthird/hapi-hooks","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/firstandthird/hapi-hooks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/firstandthird","download_url":"https://codeload.github.com/firstandthird/hapi-hooks/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-hooks/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261487192,"owners_count":23166037,"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":["hapi-plugin"],"created_at":"2025-01-19T10:14:26.313Z","updated_at":"2025-06-23T13:33:46.768Z","avatar_url":"https://github.com/firstandthird.png","language":"JavaScript","readme":"# hapi-hooks\n\nA 'hook' is a task that is spawned by a server event, but is performed independently of that event. This frees up the server to respond to requests and do other important work, while an independent process polls for new hooks and handles processing and updating them. This module requires access to a mongo server that is used to track the hooks.\n\n*__Use cases__*:\n- adding users or updating lists\n- sending emails\n- metrics\n- aggregate counts\n- long running processes\n- notification systems\n\n```\ninstall hapi-hooks\n```\n\nExample (where ```server``` is your initialized hapi server):\n\n```js\nserver.method('addUserObject', (data, callback) =\u003e {\n  ABunchODBStuff(data, (err, result) =\u003e {\n    if (!err) {\n      console.log(\"added the user object!\");\n    }\n    return callback(err, result);\n  });\n});\nserver.method('sendEmail', (data, callback) =\u003e {\n  console.log(\"emailing an email to %s\", data.email);\n  sendSomeEmail(data.email, callback);\n});\n\nserver.method('bigLongCalculation', (data) =\u003e {\n  console.log(\"calculating the widget number\");\n  return callback(null, performBigLongCalculation(data.widgetNumber));\n});\n\nserver.register({\n  register: require('hapi-hooks'),\n  options: {\n    interval: 30000, // checks for new hooks to process every 3 seconds\n    hooks: {\n      'create user': [\n        // actions can just be the name of the server method to invoke:\n        'addUserObject',\n        // actions can also be given default params:\n        {\n            method: 'sendEmail',\n            data: { smtpHost: 'http://www.smtp.com', smtpLogin: 'myLogin', smtpPassword: 'insecure1'}\n        }\n        {\n          method: 'bigLongCalculation',\n          data: { x: 42 }\n        }\n      ]\n    }\n  }\n}, () =\u003e {\n  server.methods.hook('create user', {\n    email: 'superuser@example.com',\n    widgetNumber: 152\n  });\n});\n```\n\nOutput may not appear until up to 3 seconds after the call to ```server.methods.hook```, it will look something like:\n```sh\nemailing an email to superuser@example.com\nadded the user object\ncalculating the widget number\n```\n\nNote that the server methods within an hook call are invoked in parallel, so the above example outputs could be printed in any order.\n\n### Recurring Support\n\nPass the following options:\n\n`runEvery` - A laterjs supported string, ex: `at 5pm sunday`\n`hookId` - A unique identifier. Used to prevent duplicate hooks (Recommended for all hooks)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstandthird%2Fhapi-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffirstandthird%2Fhapi-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstandthird%2Fhapi-hooks/lists"}