1
1
# Addons
2
2
3
3
Node.js Addons are dynamically-linked shared objects, written in C or C++, that
4
- can be loaded into Node.js using the ` require() ` function, and used just as if
5
- they were an ordinary Node.js module. They are used primarily to provide an
6
- interface between JavaScript running in Node.js and C/C++ libraries.
4
+ can be loaded into Node.js using the [ ` require() ` ] [ require ] function, and used
5
+ just as if they were an ordinary Node.js module. They are used primarily to
6
+ provide an interface between JavaScript running in Node.js and C/C++ libraries.
7
7
8
8
At the moment, the method for implementing Addons is rather complicated,
9
9
involving knowledge of several components and APIs :
@@ -12,7 +12,7 @@ involving knowledge of several components and APIs :
12
12
JavaScript implementation. V8 provides the mechanisms for creating objects,
13
13
calling functions, etc. V8's API is documented mostly in the
14
14
` v8.h ` header file (` deps/v8/include/v8.h ` in the Node.js source
15
- tree), which is also available [ online] [ ] .
15
+ tree), which is also available [ online] [ v8-docs ] .
16
16
17
17
- [ libuv] [ ] : The C library that implements the Node.js event loop, its worker
18
18
threads and all of the asynchronous behaviors of the platform. It also
@@ -118,7 +118,7 @@ Node.js as part of `npm`. This version is not made directly available for
118
118
developers to use and is intended only to support the ability to use the
119
119
` npm install ` command to compile and install Addons. Developers who wish to
120
120
use ` node-gyp ` directly can install it using the command
121
- ` npm install -g node-gyp ` . See the ` node-gyp ` [ installation instructions] for
121
+ ` npm install -g node-gyp ` . See the ` node-gyp ` [ installation instructions] [ ] for
122
122
more information, including platform-specific requirements.*
123
123
124
124
Once the ` binding.gyp ` file has been created, use ` node-gyp configure ` to
@@ -134,7 +134,7 @@ version of `node-gyp` to perform this same set of actions, generating a
134
134
compiled version of the Addon for the user' s platform on demand.
135
135
136
136
Once built, the binary Addon can be used from within Node.js by pointing
137
- `require()` to the built `addon.node` module:
137
+ [ `require()`][require] to the built `addon.node` module:
138
138
139
139
```js
140
140
// hello.js
@@ -184,17 +184,17 @@ dependencies.
184
184
### Loading Addons using require ()
185
185
186
186
The filename extension of the compiled Addon binary is `.node` (as opposed
187
- to ` .dll ` or ` .so ` ). The ` require() ` function is written to look for files
188
- with the ` .node ` file extension and initialize those as dynamically-linked
187
+ to ` .dll ` or ` .so ` ). The [ ` require() ` ] [ require ] function is written to look for
188
+ files with the ` .node ` file extension and initialize those as dynamically-linked
189
189
libraries.
190
190
191
- When calling ` require() ` , the ` .node ` extension can usually be
191
+ When calling [ ` require() ` ] [ require ] , the ` .node ` extension can usually be
192
192
omitted and Node.js will still find and initialize the Addon. One caveat,
193
193
however, is that Node.js will first attempt to locate and load modules or
194
194
JavaScript files that happen to share the same base name. For instance, if
195
195
there is a file ` addon.js ` in the same directory as the binary ` addon.node ` ,
196
- then ` require('addon') ` will give precedence to the ` addon.js ` file and load it
197
- instead.
196
+ then [ ` require('addon') ` ] [ require ] will give precedence to the ` addon.js ` file
197
+ and load it instead.
198
198
199
199
## Native Abstractions for Node.js
200
200
@@ -215,9 +215,10 @@ illustration of how it can be used.
215
215
## Addon examples
216
216
217
217
Following are some example Addons intended to help developers get started. The
218
- examples make use of the V8 APIs. Refer to the online [ V8 reference] [ ] for help
219
- with the various V8 calls, and V8's [ Embedder's Guide] [ ] for an explanation of
220
- several concepts used such as handles, scopes, function templates, etc.
218
+ examples make use of the V8 APIs. Refer to the online [ V8 reference] [ v8-docs ]
219
+ for help with the various V8 calls, and V8's [ Embedder's Guide] [ ] for an
220
+ explanation of several concepts used such as handles, scopes, function
221
+ templates, etc.
221
222
222
223
Each of these examples using the following ` binding.gyp ` file:
223
224
@@ -1077,14 +1078,14 @@ Test in JavaScript by running:
1077
1078
const addon = require('./build/Release/addon');
1078
1079
```
1079
1080
1080
- [ online]: https:// v8docs.nodesource.com/
1081
- [libuv]: https:// github.com/libuv/libuv
1081
+ [ bindings]: https:// github.com/TooTallNate/node-bindings
1082
1082
[download]: https:// github.com/nodejs/node-addon-examples
1083
- [node-gyp]: https:// github.com/nodejs/node-gyp
1084
- [V8 reference]: https:// v8docs.nodesource.com/
1085
1083
[Embedder' s Guide]: https://developers.google.com/v8/embed
1086
- [Native Abstrations for Node.js]: https://github.com/nodejs/nan
1087
1084
[examples]: https://github.com/nodejs/nan/tree/master/examples/
1088
- [bindings]: https://github.com/TooTallNate/node-bindings
1089
- [Linking to Node.js' own dependencies]: #linking-to-nodejs-own-dependencies
1090
1085
[installation instructions]: https://github.com/nodejs/node-gyp#installation
1086
+ [libuv]: https://github.com/libuv/libuv
1087
+ [Linking to Node.js' own dependencies]: #linking-to-nodejs-own-dependencies
1088
+ [Native Abstrations for Node.js]: https:// github.com/nodejs/nan
1089
+ [node-gyp]: https:// github.com/nodejs/node-gyp
1090
+ [require]: globals.html#globals_require
1091
+ [v8-docs]: https:// v8docs.nodesource.com/
0 commit comments