{"id":13657610,"url":"https://github.com/vshymanskyy/node-inline-cpp","last_synced_at":"2025-04-13T15:52:52.279Z","repository":{"id":57153740,"uuid":"142214729","full_name":"vshymanskyy/node-inline-cpp","owner":"vshymanskyy","description":"Inline C++ with Node.js","archived":false,"fork":false,"pushed_at":"2018-08-02T10:17:12.000Z","size":40,"stargazers_count":168,"open_issues_count":0,"forks_count":4,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-10T17:20:39.491Z","etag":null,"topics":["cplusplus","cpp","inline","inline-cpp","native","node-napi"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/vshymanskyy.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-07-24T21:28:04.000Z","updated_at":"2024-08-08T15:54:50.000Z","dependencies_parsed_at":"2022-09-07T08:41:37.924Z","dependency_job_id":null,"html_url":"https://github.com/vshymanskyy/node-inline-cpp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vshymanskyy%2Fnode-inline-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vshymanskyy%2Fnode-inline-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vshymanskyy%2Fnode-inline-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vshymanskyy%2Fnode-inline-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vshymanskyy","download_url":"https://codeload.github.com/vshymanskyy/node-inline-cpp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248741148,"owners_count":21154249,"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":["cplusplus","cpp","inline","inline-cpp","native","node-napi"],"created_at":"2024-08-02T05:00:46.544Z","updated_at":"2025-04-13T15:52:52.231Z","avatar_url":"https://github.com/vshymanskyy.png","language":"JavaScript","readme":"[![NPM version](https://img.shields.io/npm/v/inline-cpp.svg)](https://www.npmjs.com/package/inline-cpp)\n[![NPM download](https://img.shields.io/npm/dm/inline-cpp.svg)](https://www.npmjs.com/package/inline-cpp)\n[![GitHub issues](https://img.shields.io/github/issues/vshymanskyy/node-inline-cpp.svg)](https://github.com/vshymanskyy/node-inline-cpp/issues)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/vshymanskyy/node-inline-cpp)\n\n# inline-cpp\nInline C++ with Node.js\n\n**Works on:** \n\u003cimg src=\"https://cdn.rawgit.com/simple-icons/simple-icons/develop/icons/linux.svg\" width=\"18\" height=\"18\" /\u003e Linux,\n\u003cimg src=\"https://cdn.rawgit.com/simple-icons/simple-icons/develop/icons/windows.svg\" width=\"18\" height=\"18\" /\u003e Windows,\n\u003cimg src=\"https://cdn.rawgit.com/simple-icons/simple-icons/develop/icons/apple.svg\" width=\"18\" height=\"18\" /\u003e MacOS\n\n**Purpose:**\n- Simplify native module prototyping. Enable native code in Node.js REPL.\n- Allow JS scripts to generate C++ code and run it dynamically.\n- Popularise NAPI usage and `node-addon-api`.\n- This is **NOT** intended to be used as native module replacement!  \nIf you want to publish a native module, please package it as required by `node-gyp`.\n\n## Installation\n\n```sh\nnpm install --save inline-cpp\n```\nor install it globally (it works with Node.js REPL):\n```sh\nnpm install -g inline-cpp\n```\n\n## Usage\n\n```js\n// test.js\nconst compile = require('inline-cpp');\n\nconst hello = compile `\n  String func(const CallbackInfo\u0026 info) {\n    return String::New(info.Env(), \"Hello world from C++!\");\n  }\n`\n\nconsole.log(hello())\n```\nNow run it:\n```sh\n➜ node test.js\nHello world from C++!\n```\n\nThe first time you run the script, it takes longer to execute. For each inline block of code, a native module will be generated, compiled with `node-gyp` and loaded dynamically. If the module `Init` function is not defined, it is generated as well.  \nThe next time you run the script, it will reuse previously generated module, so it will run instantly (unless you change the inline C++ code).  \n\nFor more C++ code examples, see [node-addon-api](https://github.com/nodejs/node-addon-api#examples)  \nFor more `inline-cpp` API examples, see [examples on github](https://github.com/vshymanskyy/node-inline-cpp/tree/master/examples)\n\n## API\n\n`inline-cpp` supports several invocation methods.\n\nPass some code as string to build it with default options.\n```js\nconst InlineCPP = require('inline-cpp');\nInlineCPP('code')\n```\n\nYou can also pass code using [tagged template syntax](https://developers.google.com/web/updates/2015/01/ES6-Template-Strings#tagged_templates).\n```js\nInlineCPP `code`\n```\n\nPass an object to create a new compiler with custom options.  \nOptions will get passed to `node-gyp` target.  \n```js\nconst customCompiler = InlineCPP({ ... })\n```\n\nIf the code block only contains a single function, the compiler returns the function.  \nIf it contains multiple functions or custom `Init`, the module itself is returned.\n\n## Disclaimer\n\nThis is just a prototype. I created this to check the general concept.  \nYou're welcome to contribute! Here are some ideas:\n\n- [x] Parse/Find all functions in the block of code, add them to exports\n- [ ] Use node-gyp directly, instead of invoking `node node-gyp.js`\n- [ ] Improve error handling/reporting\n- [ ] Create advanced usage examples\n- [ ] Cleanup unused modules from cache periodically\n- [ ] ...\n\n## Debugging\n\nYou can enable debug output by setting env. variable: `DEBUG=inline-cpp`\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvshymanskyy%2Fnode-inline-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvshymanskyy%2Fnode-inline-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvshymanskyy%2Fnode-inline-cpp/lists"}