Node: What are Node.js "Linked" modules?

Created on 19 Apr 2017  路  11Comments  路  Source: nodejs/node

When I was going through the source code, I found this in node.cc,

// "Linked" modules are included as part of the node project.
// Like builtins they are registered *before* node::Init runs.
mp->nm_flags = NM_F_LINKED;

Does anybody know what "Linked" modules are? @bnoordhuis maybe?


cc @addaleax

doc good first issue help wanted lib / src

Most helpful comment

I assume so, at least at the time, otherwise why bother making a pull request? Both features where requested and implemented by non-collaborators.

Documenting it: no reason not to, I suppose.

All 11 comments

It's probably this in the build script:

parser.add_option("--link-module",
    action="append",
    dest="linked_module",
    help="Path to a JS file to be bundled in the binary as a builtin."
         "This module will be referenced by path without extension."
         "e.g. /root/x/y.js will be referenced via require('root/x/y')."
         "Can be used multiple times")

@mscdex That鈥檚 something different. The linked modules the C++ source is talking about would be native modules that are compiled into (or LD_PRELOLADed into?) the node executable itself, not JS code.

Well, that's not confusing ;-)

The configure switch is for baking third-party JS source code into the binary, NM_F_LINKED is for bundling add-ons into the binary. Unfortunate name clash, yes.

@bnoordhuis Is there anybody who uses that feature? Would documenting it be a good idea?

I assume so, at least at the time, otherwise why bother making a pull request? Both features where requested and implemented by non-collaborators.

Documenting it: no reason not to, I suppose.

Hi I'd like to work on this. This is my first time working on open source and I was wondering which part of the documentation this should go into, and generally the relevant parts of the source I should be looking at.

I guess it should go somewhere in https://nodejs.org/api/modules.html (source here)?

As mentioned above, for the Native module you probably want to start here:

https://github.com/nodejs/node/blob/4359a93cc9462362ec2ae73189c92521fa386906/src/node.cc#L2595-L2599

For the js module you probably want to start here:

https://github.com/nodejs/node/blob/201ecef767d0e4b8ea07e650646bd6811156dc12/configure#L152-L158

@bnoordhuis are the two features functionally identical, except for the fact that one is for native addons and one is for js addons?

Awesome, thanks for the tips @gibfahn I'll look into it.

Reopen since the OP is asking about native modules and they are still not documented. Should be fixed by https://github.com/nodejs/node/pull/19112

Sounds like this was addressed by @joyeecheung above. Closing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mcollina picture mcollina  路  3Comments

srl295 picture srl295  路  3Comments

willnwhite picture willnwhite  路  3Comments

addaleax picture addaleax  路  3Comments

danialkhansari picture danialkhansari  路  3Comments