{"id":32571449,"url":"https://github.com/humio/humio-js","last_synced_at":"2025-10-29T08:27:32.844Z","repository":{"id":45371931,"uuid":"118116559","full_name":"humio/humio-js","owner":"humio","description":"A Javascript client for Humio.","archived":false,"fork":false,"pushed_at":"2022-07-20T09:48:18.000Z","size":101,"stargazers_count":5,"open_issues_count":5,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-02-09T02:02:45.506Z","etag":null,"topics":["humio","javascript","logging","logging-js","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/humio.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":"2018-01-19T11:19:48.000Z","updated_at":"2024-02-09T02:02:45.507Z","dependencies_parsed_at":"2022-09-01T16:21:25.490Z","dependency_job_id":null,"html_url":"https://github.com/humio/humio-js","commit_stats":null,"previous_names":["humio/humio-node"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/humio/humio-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humio%2Fhumio-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humio%2Fhumio-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humio%2Fhumio-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humio%2Fhumio-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/humio","download_url":"https://codeload.github.com/humio/humio-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humio%2Fhumio-js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281586969,"owners_count":26526656,"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","status":"online","status_checked_at":"2025-10-29T02:00:06.901Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["humio","javascript","logging","logging-js","nodejs"],"created_at":"2025-10-29T08:27:30.753Z","updated_at":"2025-10-29T08:27:32.826Z","avatar_url":"https://github.com/humio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Humio Javascript Client \u003ca href=\"https://www.npmjs.com/package/humio\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/humio.svg\" alt=\"\" /\u003e\u003c/a\u003e\n\nWith Humio's Javascript client you can do Execute Queries and Searches and Log to Humio.\n\n## Usage\n\n```\nnpm install -S humio\n```\n\nDepending on your environment you should use the import the appropriate file:\n\n\n### NodeJs, Webpack or similar\n\n```javascript\nimport Humio from 'humio';\n// or\nvar Humio = require('humio')\n```\n\n### Vanilla Browser\n\n```html\n\u003cscript src=\"\u003cpath-to-humio\u003e/dist/humio.browser.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n    window.Humio\n\u003c/script\u003e\n```\n\n### Creating a client instance\n\n```javascript\nconst humio = new Humio({\n  apiToken: \"xyz...\", // needed if you use the administration api\n  ingestToken: \"xyz...\", // the default ingest tokens to use for #run and #stream\n  host: \"cloud.humio.com\", // the host name\n  port: 443, // default (443), the port Humio is run on\n  basePath: \"/\", // default (\"/\"), basePath prepended to all API URLs.\n  repository: \"sandbox\" // default (\"sandbox\"), the default repository (or view) to work with\n});\n```\n\n### Searching Humio\n\nThis search will count the number of new users in our system in the past 10 minutes.\n\n```javascript\nlet count = null;\n\nclient.run({ queryString: '\"User Created\" | count()', start: \"10m\", isLive: true })\n  .then((result) =\u003e {\n    if (result.status === \"success\") {\n      count = parseInt(result.data[0]._count);\n      // Alternatively use the helper function: Humio.count(result)\n    } else {\n      console.error(\"Search Error\", result.error);\n    }\n  }).catch(console.error);\n```\n\nYou should always check `status` on `result`. Humio will not report query errors\nin the catch clause, because the operation was a success, but your input was\nlikely not correct. The error reason is stored in `result.error`.\n\nIf the request fails do so a connection error or similar it will be reported in\n`catch`.\n\nNotice that even though `_count` is a number we have to parse it using\n`parserInt`. That is because in Humio everything is just a string, and is\nreturned as a string.\n\nThere are two functions used for querying Humio:\n\n- `stream`\n- `run`\n\n#### Stream\n\nThe `stream` function should be used when you have a need to stream results as they\nare found by Humio. You should use `stream` for getting very large result sets –\nHumio does not need to buffer then since each event is sent the instant they are found.\n\nWhile it is possible use `stream()` execute aggregate functions like `timechart` or `count`,\nit does not make much sense stream it those result. That is where `run` fits in.\n\n_In a future version of Humio you might not be able to use `stream` for aggregates,\nso we recommend that you don't._\n\n#### Run\n\nThe `run` function is meant primarily for aggregate functions and small filter\nsearches with smaller result sets. It will start a search in Humio and periodically\nreturn partial results as the search progresses.\n\nE.g. the query `service=kubernetes | count()` will return the number events with\nthe field `service=kubernetes`. As Humio completes the search it will periodically\nsend back the result so far.\n\n```javascript\nclient.run({query: \"service=kubernetes | count()\", onPartialResult: (result, progress) =\u003e {\n  console.log(Humio.count(result), 100 * progress + \"%\");\n}});\n```\n\n### Sending Events to Humio\n\n```javascript\n\n// Sending Structured Data (JSON)\n\nconst linux = {\n  coreTemperature: \"92F\",\n  server: \"andromida-2\",\n  kernelVersion: \"4.14.14\",\n  eventType: 'CORE_DUMP'\n};\n\nhumio.sendJson(linux);\n\n// You can specify additional fields to be added to the data,\n// without having to modify `linux`.\n\nhumio.sendJson(linux, { additionalFields: { \"example\": \"more-fields\" } });\n\n// By default Humio uses the current time as the event's timestamp.\n// You can override it, if the event did not happen right now.\n\nhumio.sendJson(linux, {\n  timestamp: \"2018-01-19T12:58:34.441Z\",\n  additionalFields: { \"example\": \"custom-timestamp\" }\n});\n```\n\n### Sending Unstructured Logs to Humio\n\nApart from sending json you can also send _normal_ unstructured log lines to Humio.\n\nYou will need to assign a parser to the ingest token in Humio before using the\nunstructured ingest API.\n\n```javascript\n\nhumio.sendMessage(\n  \"2018-01-19T12:58:34.441Z [warn] User login failed. username=admin ip=101.127.184.11\",\n  {'domain': 'example.com'}\n);\n```\n\nIf you are planning on using Humio for logging, consider using a log shipper\nlike [Filebeat](https://cloud.humio.com/docs/first-time-use/index.html) instead.\nIt will handle connection problems, resubmission, etc. for you and is\ncompatible with Humio. This goes for structured events as well.\n\nFor an serverless environment on the other hand, `humio-node` could be a great\nfit for logging.\n\n## Tips\n\n### Additional Fields\n\nIt is also possible to add additional fields at the client level instead of\npassing it to every function call.\n\n```javascript\nconst humio = new Humio({ ..., additionalFields: { service: \"my-service\", domain: \"example.com\" } });\n```\n\nThese fields will be added to each call to `sendJson` and `sendMessage`.\n\n### Metadata\n\nHumio also adds metadata to the events e.i. `@client` (always \"humio-node\"),\n`@clientVersion` (the current version of humio-node), and `@session`.\n\n`@session` makes it easy to track events over several messages in Humio.\nYour system might have this data already and you can exclude `@session`\nusing:\n\n```javascript\nhumio.sendJson(linux, {\n  includeClientMetadata: false,\n  includeSessionId: false\n});\n```\n\n\n### TODO\n\n- [x] Live Queries\n- [ ] Buffered Sending (don't send messages one at a time)\n- [x] Error handling, callback function (or Promise)\n- [ ] Resubmission and back-off\n- [x] Streaming Search / Partial Results\n- [ ] Ability to cancel running search (works for #stream, not #run)\n\n## Contribute\n\nPlease Contribute if you see something missing or find a bug,\nPR's are always welcome.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhumio%2Fhumio-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhumio%2Fhumio-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhumio%2Fhumio-js/lists"}