{"id":21195597,"url":"https://github.com/openpeeps/denim","last_synced_at":"2025-07-10T04:30:28.019Z","repository":{"id":168757699,"uuid":"382238781","full_name":"openpeeps/denim","owner":"openpeeps","description":"Node 💖 Nim = Denim! Build powerful NodeJS / BunJS addons with Nim language via Node API (NAPI)","archived":false,"fork":false,"pushed_at":"2024-05-20T12:49:40.000Z","size":2797,"stargazers_count":39,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-05-20T13:54:19.295Z","etag":null,"topics":["bindings","cli-tool","denim","javascript","napi","napi-nim","native-addon","nim-lang","node","node-addon-api","nodejs-addon","nodejs-native-addon","openpeeps","toolkit"],"latest_commit_sha":null,"homepage":"https://openpeeps.github.io/denim/","language":"Nim","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/openpeeps.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-02T05:21:39.000Z","updated_at":"2024-05-20T12:49:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"56d9465c-5ad0-4459-a475-434603151e5f","html_url":"https://github.com/openpeeps/denim","commit_stats":null,"previous_names":["openpeeps/denim"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openpeeps%2Fdenim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openpeeps%2Fdenim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openpeeps%2Fdenim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openpeeps%2Fdenim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openpeeps","download_url":"https://codeload.github.com/openpeeps/denim/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225618234,"owners_count":17497482,"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":["bindings","cli-tool","denim","javascript","napi","napi-nim","native-addon","nim-lang","node","node-addon-api","nodejs-addon","nodejs-native-addon","openpeeps","toolkit"],"created_at":"2024-11-20T19:29:04.769Z","updated_at":"2025-07-10T04:30:28.013Z","avatar_url":"https://github.com/openpeeps.png","language":"Nim","readme":"\u003cp align=\"center\"\u003e\n  Denim - Native NodeJS/BunJS addons powered by Nim\u003cbr\u003e👑 Written in Nim language\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ccode\u003enimble install denim\u003c/code\u003e\u003cbr\u003e\u003cbr\u003e\n  \u003ca href=\"https://openpeeps.github.io/denim\"\u003eAPI reference\u003c/a\u003e\u003cbr\u003e\n  \u003cimg src=\"https://github.com/openpeeps/denim/workflows/test/badge.svg\" alt=\"Github Actions\"\u003e  \u003cimg src=\"https://github.com/openpeeps/denim/workflows/docs/badge.svg\" alt=\"Github Actions\"\u003e\n\u003c/p\u003e\n\n## 😍 Key Features\n- [x] CLI build via Nim + `node-gyp` or CMake.js (faster)\n- [ ] CLI publish to NPM\n- [x] Low-level API\n- [x] High-level API\n- [x] Open Source | `MIT` License\n- [x] Written in 👑 Nim language\n\n## Requirements\n- Nim (latest / via `choosenim`)\n- Node (latest) and `node-gyp` or CMake.js\n\n### CLI\nDenim is a hybrid package, you can use it as a CLI for compiling Nim code to `.node` addon via `Nim` + `NodeGYP` and as a library for importing NAPI bindings.\n\nSimply run `denim -h`\n```\nDENIM 🔥 Native Node/BunJS addons powered by Nim\n\n  build \u003centry\u003e \u003clinks\u003e --cmake --yes --verbose          Build Nim project to a native NodeJS addon\n  publish                                                Publish addon to NPM (requires npm cli)\n```\n\nUse Denim as a Nimble task:\n```nim\ntask napi, \"Build a .node addon\":\n  exec \"denim build src/myprogram.nim\"\n```\n\nWant to pass custom flags to Nim Compiler? Create a `.nims` file:\n```nim\nwhen defined napibuild:\n  # add some flags\n```\n\n\u003e __Note__ Check fully-working examples in [/tests](https://github.com/openpeeps/denim/tree/main/tests)\n\n### Defining a module\n\nUse `init` to define module initialization.\n```nim\nwhen defined napibuild:\n  # optionally, you can use `napibuild` flag to wrap your code\n  # this flag is set when compiling via `denim build src/myprogram.nim` \n  import denim # import NAPI bindings \n  init proc(module: Module) =\n    # registering properties and functions here\n    # this is similar with javascript `module.exports`\nelif isMainModule:\n  echo \"just a normal nim program\"\n```\n\n### Nim Type to NapiValueType\nUse low-level API to convert Nim values to `napi_value` (`NapiValueType`).\nUse `assert` to check if a low-level function returns a success or failure. [Currently, the following status codes are supported](https://nodejs.org/api/n-api.html#napi_status)\n\n```nim\nimport denim\ninit proc(module: Module) =\n  module.registerFn(0, \"awesome\"):\n    var str2napi: napi_value\n    var str = \"Nim is awesome!\"\n    assert Env.napi_create_string_utf8(str, str.len.csize_t, str2napi.addr) \n    return str2napi\n```\n\nAlternatively, use `%*` to auto-convert Nim values to `NapiValueType`.\n```nim\nlet\n  a: napi_value = %* \"Hey\"\n  b: napi_value = %* true\nassert a.kind == napi_string\nassert b.kind == napi_boolean\n```\n\n### Exports\nSince `v0.1.5`, you can use `{.export_napi.}` pragma to export functions and object properties.\n\n```nim\nimport denim\n\ninit proc(module: Module): # the name `module` is required\n  proc hello(name: string) {.export_napi} =\n    ## A simple function from Nim\n    return %*(\"Hello, \" \u0026 args.get(\"name\").getStr)\n\n  var awesome {.export_napi.} = \"Nim is Awesome!\"\n```\n\nCalling a function/property from Node/Bun\n```js\nconst app = require('myaddon.node')\nconsole.log(app.hello(\"World!\"))       // Hello, World!\nconsole.log(app.awesome)               // Nim is Awesome!\n```\n\n### Built-in type checker\n```js\napp.hello()\n```\n\n```\n/*\n * A simple function from Nim\n * @param {string} name\n * @return {string}\n */\nType mismatch parameter: `name`. Got `undefined`, expected `string`\n```\n\n## Real-World Examples\n- **Tim Engine** \u0026mdash; A template engine. [GitHub](https://github.com/openpeeps/tim)\n- **Bro** \u0026mdash; A fast stylesheet language, alternative to SassC, DartSass. [GitHub](https://github.com/openpeeps/bro)\n- **HappyX** \u0026mdash; Macro-oriented asynchronous web-framework written in Nim. [GitHub](https://github.com/HapticX/happyx)\n\n### Todo\n- Option to link external C Headers/libraries\n- Extend High-level API with compile-time functionality. \n\n### ❤ Contributions \u0026 Support\n- 🐛 Found a bug? [Create a new Issue](https://github.com/openpeeps/denim/issues)\n- 👋 Wanna help? [Fork it!](https://github.com/openpeeps/denim/fork)\n- 😎 [Get €20 in cloud credits from Hetzner](https://hetzner.cloud/?ref=Hm0mYGM9NxZ4)\n\n### 🎩 License\nDenim | MIT license. [Made by Humans from OpenPeeps](https://github.com/openpeeps)\u003cbr\u003e\nThanks to [Andrew Breidenbach](https://github.com/AjBreidenbach) and [Andrei Rosca](https://github.com/andi23rosca) for their work.\u003cbr\u003e\n\nCopyright \u0026copy; 2023 OpenPeeps \u0026 Contributors \u0026mdash; All rights reserved.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenpeeps%2Fdenim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenpeeps%2Fdenim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenpeeps%2Fdenim/lists"}