![]() ![]() The testBasic function then calls the HelloWorld function and verifies the result. ![]() The function is loaded into the HelloWorld variable using the require command. Recall that the sole export from the binding is the HelloWorld function. ![]() This code demonstrates how to load and call the HelloWorld function using JavaScript. log ( "Tests passed- everything looks OK!" ) doesNotThrow (testBasic, undefined, "testBasic threw an expection" ) Ĭonsole. As the package documentation describes, generator-napi-module relies on Yeoman which must also be installed:Īssert. The easiest way to create a new Node-API project is to use the generator-napi-module package. You can determine the version of Node you’re running with the command node -v. To see which versions of Node support Node-API, refer to the Node-API Version Matrix. You will need a copy of Node that supports Node-API in order to develop and run Node-API code. This tutorial has been tested with Node 10.10.0 and is known to fail with older versions of Node. Since then, it’s undergone a number of refinements. Node-API has been in public release and active development starting with Node 8.0.0. This package makes working with Node-API much easier as it implements a very nice object model and abstracts away much of the detailed coding that would otherwise be required, while retaining the Node-API promise of ABI stability and forward compatibility. If you need low-level access to the intricacies of Node, this is the tool for you.Īlternatively, there is the node-addon-api package which adds a C++ wrapper to the Node-API code built into Node. The “C level” code is built entirely into Node itself and is very well documented on the Node documentation pages. Before you start, make sure you’ve got all the necessary prerequisites and tools installed.Īs you select where to begin, you should be aware that Node-API operates at two levels which we can think of as the “C level” and the “C++ level”. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |