{"id":28191614,"url":"https://github.com/modelfoxdotdev/node_api","last_synced_at":"2025-05-16T11:10:43.100Z","repository":{"id":57645326,"uuid":"377537135","full_name":"modelfoxdotdev/node_api","owner":"modelfoxdotdev","description":"Write Node.js native addons in Rust with bindings to Node-API.","archived":false,"fork":false,"pushed_at":"2022-02-27T17:15:41.000Z","size":86,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-15T23:16:54.735Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","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/modelfoxdotdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2021-06-16T15:07:52.000Z","updated_at":"2023-05-12T15:00:02.000Z","dependencies_parsed_at":"2022-09-08T15:10:28.243Z","dependency_job_id":null,"html_url":"https://github.com/modelfoxdotdev/node_api","commit_stats":null,"previous_names":["tangramdotdev/node_api"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modelfoxdotdev%2Fnode_api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modelfoxdotdev%2Fnode_api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modelfoxdotdev%2Fnode_api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modelfoxdotdev%2Fnode_api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/modelfoxdotdev","download_url":"https://codeload.github.com/modelfoxdotdev/node_api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254518401,"owners_count":22084376,"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":"2025-05-16T11:10:23.380Z","updated_at":"2025-05-16T11:10:43.096Z","avatar_url":"https://github.com/modelfoxdotdev.png","language":"Rust","readme":"# node_api\n\nThis crate provides bindings to the [Node-API](https://nodejs.org/docs/latest/api/n-api.html) C API, making it easy to write Node native addons in Rust.\n\n## Example\n\nWrite your native addon in Rust:\n\n```rust\nnode_api::init!(init);\n\nfn init(env: node_api::Env, exports: node_api::Value) -\u003e Result\u003cnode_api:Value, String\u003e {\n  let exports = export.as_object();\n  let key = node_api::String::new(env, \"add\")?;\n  let value = node_api::Function::new(env, \"add\", add)?;\n  exports.set(key, value);\n  Ok(exports.value())\n}\n\n#[node_api::function]\nfn add(a: u64, b: u64) -\u003e Result\u003cu64, String\u003e {\n  Ok(a + b)\n}\n```\n\nThen load it in Node.js.\n\n```javascript\nlet native = require(\"./add.node\");\nassert(native.add(3, 4) === 7);\n```\n\nSee the examples folder for a complete example.\n\n## Serde integration\n\nTo make it easy to move data structures between Rust and Node.js, the node_api crate supports integration with [serde](https://serde.rs).\n\n```rust\n#[derive(serde::Serialize, serde::Deserialize)]\nstruct Contact {\n  name: String,\n  email: String,\n}\n\n#[node_api::function]\nfn contact(env: node_api::Env) -\u003e node_api::Result\u003cContact\u003e {\n  Ok(Contact {\n    name: \"John Doe\".to_owned(),\n    email: \"john.doe@example.com\".to_owned(),\n  })\n}\n```\n\n```javascript\nlet contact = native.contact();\nconsole.log(\"Contact name: \" + contact.name);\nconsole.log(\"Contact email: \" + contact.email);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodelfoxdotdev%2Fnode_api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmodelfoxdotdev%2Fnode_api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodelfoxdotdev%2Fnode_api/lists"}