Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS Code in the native node module #528

Closed
sudhakar3697 opened this issue Aug 22, 2019 · 3 comments
Closed

JS Code in the native node module #528

sudhakar3697 opened this issue Aug 22, 2019 · 3 comments

Comments

@sudhakar3697
Copy link

sudhakar3697 commented Aug 22, 2019

Is it possible to access the following variants of node modules inside the N-API addon code(C/C++).

  1. Built-in Node module (like fs, http).
  2. Node module written in Javascript.
  3. Native node module written using (NAN or oth).
  4. Native node module written using N-API.

Thank you.

@legendecas
Copy link
Member

If I got it right, the key might be a module API in N-API to allow N-API modules to directly access other type of modules. Currently you have to pass require function or module instance to N-API modules on a setup phase from JS. With require there is no differences between these 4 types of modules AFAIK.

A module API is being proposed on nodejs/node#28464.

@mhdawson
Copy link
Member

@sudhakar3697 you can call JavaScript functions, but is up to you to get those to the N-API module. For example if you pass the result of fs = require('fs') to an N-API function it can use N-API methods to get fields/functions on that an then call them.

Having said that it might be easier to keep some of that functionality in JS and call a higher level function from the N-API C function as opposed to making many of those calls in the N-API functcion. I also believe it would likely be better optimized with more of the calls together at the JS level as each back and forth adds overhead.

@sudhakar3697
Copy link
Author

sudhakar3697 commented Aug 30, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants