You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Perhaps the most popular use for N-API is making the capabilities of an existing C/C++ library available to JavaScript programmers. This permits you to leverage the investment you've already made in your existing code, making it available to a whole new population of JavaScript programmers and projects.
9
+
Perhaps the most popular use for Node-API is making the capabilities of an existing C/C++ library available to JavaScript programmers. This permits you to leverage the investment you've already made in your existing code, making it available to a whole new population of JavaScript programmers and projects.
10
10
11
-
For many applications, the C/C++ code base is the reference implementation. N-API permits you to continue to refine and maintain your existing C/C++ code. Improvements to the C/C++ code are then easily transferred to the JavaScript users.
11
+
For many applications, the C/C++ code base is the reference implementation. Node-API permits you to continue to refine and maintain your existing C/C++ code. Improvements to the C/C++ code are then easily transferred to the JavaScript users.
12
12
13
13
## Access to OS resources
14
14
15
-
Some applications, like those built on [Electron](https://electronjs.org) or [NW.js](https://nwjs.io), can benefit from accessing system toolkits and APIs not currently available through Node. N-API facilities accessing these system resources.
15
+
Some applications, like those built on [Electron](https://electronjs.org) or [NW.js](https://nwjs.io), can benefit from accessing system toolkits and APIs not currently available through Node. Node-API facilities accessing these system resources.
16
16
17
17
## Computational tasks
18
18
19
-
For low-powered devices, it may make sense to code computationally intensive tasks in C or C++ and then make that code available to JavaScript using N-API. Although in many cases Node's JavaScript runtime engine will eventually compile the JavaScript down to binary, N-API offers the ability to compile the C/C++ code just once and have the binary available to Node right from the start.
19
+
For low-powered devices, it may make sense to code computationally intensive tasks in C or C++ and then make that code available to JavaScript using Node-API. Although in many cases Node's JavaScript runtime engine will eventually compile the JavaScript down to binary, Node-API offers the ability to compile the C/C++ code just once and have the binary available to Node right from the start.
Copy file name to clipboardExpand all lines: website/docs/about/what.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
id: about.what
3
-
title: What is N-API?
3
+
title: What is Node-API?
4
4
next: about.uses
5
5
---
6
6
@@ -18,18 +18,18 @@ One of the real benefits of adopting Node is the comprehensive ecosystem of Node
18
18
19
19
Besides modules written in JavaScript, Node also provides technology to enable the development of Node modules written primarily in C and C++. This permits existing C and C++ libraries to be compiled into Node *native* modules that are virtually indistinguishable from those written entirely in JavaScript.
20
20
21
-
N-API is the technology that enables the development of Node native modules.
21
+
Node-API is the technology that enables the development of Node native modules.
22
22
23
-
## N-API
23
+
## Node-API
24
24
25
-
[N-API](https://nodejs.org/api/n-api.html#n_api_n_api) is a toolkit introduced in Node 8.0.0 that acts as an intermediary between C/C++ code and the Node JavaScript engine. It permits C/C++ code to access, create, and manipulate JavaScript objects as if they were created by JavaScript code. N-API is built into Node versions 8.0.0 and later and requires no further installation.
25
+
[Node-API](https://nodejs.org/api/n-api.html#n_api_n_api) is a toolkit introduced in Node 8.0.0 that acts as an intermediary between C/C++ code and the Node JavaScript engine. It permits C/C++ code to access, create, and manipulate JavaScript objects as if they were created by JavaScript code. Node-API is built into Node versions 8.0.0 and later and requires no further installation.
26
26
27
-
There is another Node toolkit that predates N-API, [Native Abstractions for Node.js (NAN)](https://github.com/nodejs/nan) that serves a similar purpose. NAN is implemented using direct calls to the [Chrome V8](https://developers.google.com/v8/) that Node has historically used as its JavaScript engine. The disadvantage of this approach is that the NAN layer itself, as well as code that relies on it, needs to be updated every time the V8 engine used by Node is updated.
27
+
There is another Node toolkit that predates Node-API, [Native Abstractions for Node.js (NAN)](https://github.com/nodejs/nan) that serves a similar purpose. NAN is implemented using direct calls to the [Chrome V8](https://developers.google.com/v8/) that Node has historically used as its JavaScript engine. The disadvantage of this approach is that the NAN layer itself, as well as code that relies on it, needs to be updated every time the V8 engine used by Node is updated.
28
28
29
-
N-API, on the other hand, abstracts out its API from the underlying JavaScript engine. This provides two immediate benefits. The first is that N-API guarantees that the API will always be backward compatible. This means that a module you create today will continue to run on all future versions of Node without the need for running `npm install` again. Since N-API is ABI-stable, your module will continue to run even without recompilation.
29
+
Node-API, on the other hand, abstracts out its API from the underlying JavaScript engine. This provides two immediate benefits. The first is that Node-API guarantees that the API will always be backward compatible. This means that a module you create today will continue to run on all future versions of Node without the need for running `npm install` again. Since Node-API is ABI-stable, your module will continue to run even without recompilation.
30
30
31
-
The second benefit is that your module will continue to run even if Node's underlying JavaScript engine is changed. For example, there is a lot of interest in incorporating [Microsoft's ChakraCore](https://github.com/Microsoft/ChakraCore) JavaScript engine [into Node](https://github.com/nodejs/node-chakracore). Modules built on N-API will run on the ChakraCore engine without modification. In fact, they'll run without recompilation.
31
+
The second benefit is that your module will continue to run even if Node's underlying JavaScript engine is changed. For example, there is a lot of interest in incorporating [Microsoft's ChakraCore](https://github.com/Microsoft/ChakraCore) JavaScript engine [into Node](https://github.com/nodejs/node-chakracore). Modules built on Node-API will run on the ChakraCore engine without modification. In fact, they'll run without recompilation.
32
32
33
33
## node-addon-api
34
34
35
-
An important adjunct to N-API, although not strictly a part of the main project, is the npm [`node-addon-api`](https://www.npmjs.com/package/node-addon-api) module. The purpose of this module is to raise the N-API API from the level of "C" up to "C++". For many users, the object model implemented by `node-addon-api` makes the effort of creating N-API modules much easier and enjoyable.
35
+
An important adjunct to Node-API, although not strictly a part of the main project, is the npm [`node-addon-api`](https://www.npmjs.com/package/node-addon-api) module. The purpose of this module is to raise the Node-API API from the level of "C" up to "C++". For many users, the object model implemented by `node-addon-api` makes the effort of creating Node-API modules much easier and enjoyable.
Copy file name to clipboardExpand all lines: website/docs/build-tools/cmake-js.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ prev: build-tools.node-gyp
5
5
next: build-tools.node-pre-gyp
6
6
---
7
7
8
-
[CMake.js](https://github.com/cmake-js/cmake-js) is good build tool alternative to [node-gyp](node-gyp.html). CMake.js is based on the [CMake](https://cmake.org) tool which must be installed.
8
+
[CMake.js](https://github.com/cmake-js/cmake-js) is good build tool alternative to [node-gyp](node-gyp). CMake.js is based on the [CMake](https://cmake.org) tool which must be installed.
9
9
10
10
### Pros
11
11
@@ -14,7 +14,7 @@ next: build-tools.node-pre-gyp
14
14
15
15
### Cons
16
16
17
-
- Not widely adopted in the Node community.
17
+
- Not widely adopted in the Node community.
18
18
19
19
## Installation
20
20
@@ -42,7 +42,7 @@ cmake-js --version
42
42
43
43
## package.json
44
44
45
-
Your `package.json` file needs to have a couple of entires for your native module to work with CMake.js.
45
+
Your `package.json` file needs to have a couple of entires for your native module to work with CMake.js.
46
46
47
47
Since your native module needs to be compiled using CMake.js on installation, the `scripts` property of your `package.json` file needs an `install` entry to make this happen:
48
48
@@ -68,7 +68,7 @@ An alternative is to manually add the development dependency to your `package.js
When building a native module based on N-API, it is important to declare the minimum N-API version against which your module is designed to work. For CMake.js, this is accomplished by adding a line like this to the `CMakeLists.txt` file:
96
+
When building a native module based on Node-API, it is important to declare the minimum Node-API version against which your module is designed to work. For CMake.js, this is accomplished by adding a line like this to the `CMakeLists.txt` file:
97
97
98
98
```
99
99
# define NAPI_VERSION
100
100
add_definitions(-DNAPI_VERSION=3)
101
101
```
102
102
103
-
> In the absence of other requirements, N-API version 3 is a good choice as this is the N-API version active when N-API left experimental status.
103
+
> In the absence of other requirements, Node-API version 3 is a good choice as this is the Node-API version active when Node-API left experimental status.
104
104
105
105
### node-addon-api
106
106
107
-
Additional configuration values are required for N-API modules based on `node-addon-api`.
107
+
Additional configuration values are required for Node-API modules based on `node-addon-api`.
108
108
109
109
`node-addon-api` requires C++11. These configuration lines at the top of the `CMakeLists.txt` file specify this requirement:
110
110
@@ -117,7 +117,7 @@ set (CMAKE_CXX_STANDARD 11)
117
117
Modules based on `node-addon-api` include additional header files that are not part of Node itself. These lines instruct CMake.js where to find these files:
Copy file name to clipboardExpand all lines: website/docs/build-tools/node-gyp.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,18 +4,18 @@ title: node-gyp
4
4
next: build-tools.cmake-js
5
5
---
6
6
7
-
Historically, [node-gyp](https://github.com/nodejs/node-gyp) has been the build tool of choice for the Node ecosystem. The tool comes bundled with Node and is nearly universally used to build Node native modules. Most of the examples on this site use node-gyp to build the binaries.
7
+
Historically, [node-gyp](https://github.com/nodejs/node-gyp) has been the build tool of choice for the Node ecosystem. The tool comes bundled with Node and is nearly universally used to build Node native modules. Most of the examples on this site use node-gyp to build the binaries.
8
8
9
-
node-gyp is based upon Google's [GYP](https://gyp.gsrc.io/) build tool. GYP, in turn, requires Python.
9
+
node-gyp is based upon Google's [GYP](https://gyp.gsrc.io/) build tool. GYP, in turn, requires Python.
10
10
11
11
> node-gyp requires Python 2.7 or Python 3.5+ depending upon the operating system on which the native module is being built. The specifics of the requirements can be found [here](https://github.com/nodejs/node-gyp#installation).
12
12
13
-
For developers who find the node-gyp build tool too constraining, [CMake.js](cmake-js.html) is a good alternative.
13
+
For developers who find the node-gyp build tool too constraining, [CMake.js](cmake-js) is a good alternative.
14
14
15
15
### Pros
16
16
17
17
- Comes bundled with Node.
18
-
- Is nearly universally used by the Node community to build native modules.
18
+
- Is nearly universally used by the Node community to build native modules.
0 commit comments