-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
N-API: An api for embedding Node in applications #23265
Copy link
Copy link
Open
Labels
c++Issues and PRs that require attention from people who are familiar with C++.Issues and PRs that require attention from people who are familiar with C++.embeddingIssues and PRs related to embedding Node.js in another project.Issues and PRs related to embedding Node.js in another project.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.never-staleMark issue so that it is never considered staleMark issue so that it is never considered stalenode-apiIssues and PRs related to the Node-API.Issues and PRs related to the Node-API.
Metadata
Metadata
Assignees
Labels
c++Issues and PRs that require attention from people who are familiar with C++.Issues and PRs that require attention from people who are familiar with C++.embeddingIssues and PRs related to embedding Node.js in another project.Issues and PRs related to embedding Node.js in another project.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.never-staleMark issue so that it is never considered staleMark issue so that it is never considered stalenode-apiIssues and PRs related to the Node-API.Issues and PRs related to the Node-API.
Type
Projects
Status
Awaiting Triage
Is your feature request related to a problem? Please describe.
Right now there isn't a documented/stable way to use Node as a shared library inside of an application. Were one to be made using N-API, this would open up using Chakra in addition to V8 in an application.
Describe the solution you'd like
I would like for there to be stable APIs in
node_api.hfor creating/managing a Node environment.A function that does this could hypothetically look like:
The embedder could get this environment's libuv loop using
napi_get_uv_event_loop. But I would also like to have open the possibility of providing my own libuv loop that I have control over to help integrate with other event loops (e.g. Qt's event loop). This could look like:Keeping the event loop going (using
uv_runon the env's loop) would then be the embedder's responsibility.Also, right now methods like
node::CreateEnvironmentseem to always jump into a REPL, unless you provide a string to evaluate or a file to run. Tweaks to help make this nicer to use for embedding will have to be made.These APIs are just hypothetical, and will probably change when an actual attempt to implement them is made.
I am up to trying to implement this, but I would like to see what kind of discussion happens first and what other ideas people have before I start.
Implementation Progress
napi_run_script)worker_threads.Describe alternatives you've considered
I've tried using the unstable APIs, and they aren't fun to keep up with 😅
For discussions on how the shared library can be distributed, see this issue: #24028