Skip to content

JS Code in the native node module #528

Closed

Description

@sudhakar3697

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.

Activity

  1. legendecas commented on Aug 22, 2019

    @legendecas
    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.

  2. mhdawson commented on Aug 22, 2019

    @mhdawson
    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.

  3. sudhakar3697 commented on Aug 30, 2019

    @sudhakar3697
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions