Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kjhe11e/NodeJsAddons
Writing C/C++ addons for use with NodeJs
https://github.com/kjhe11e/NodeJsAddons
Last synced: about 1 month ago
JSON representation
Writing C/C++ addons for use with NodeJs
- Host: GitHub
- URL: https://github.com/kjhe11e/NodeJsAddons
- Owner: kjhe11e
- Created: 2017-03-17T21:17:42.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-10-03T03:45:53.000Z (about 5 years ago)
- Last Synced: 2024-08-03T09:06:45.404Z (4 months ago)
- Language: C++
- Homepage:
- Size: 4.13 MB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
- awesome-github-star - NodeJsAddons
README
A cumulative learning of building NodeJs addons written in C/C++.
#### Note: Node has deprecated `Nan` in favor of `N-API` -- [relevant docs](https://nodejs.org/api/addons.html)
========= *Using node-gyp* ==========
To run an application:
1) cd to the program's directory (e.g. MathAddon)
2) Run `node-gyp configure`
3) Run `node-gyp build`
4) Run `node __main.js_file__` to execute the program, e.g. `node index.js`
========== *Using Nan and CMake* ==========
CMake and Nan is a viable combination for creating NodeJs addons. IntelliJ's CLion IDE supports CMake.
-- Install cmake-js:
```
npm install cmake-js
```-- Basic project structure:
When creating a project in IntelliJ's CLion, a CMakeLists.txt file will be automatically generated.
The CMakeLists.txt file is CMake's version of node-gyp's binding.gyp file.
An example CMakeLists.txt file:
```
cmake_minimum_required(VERSION 3.5)# name of project, will be name of plugin
project(Peripherals)# build shared library named after the project from files in 'src/' dir
file(GLOB SOURCE_FILES "src/*.cpp" "src/*.h")
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})# needed to resolve nan.h library
include_directories(${CMAKE_JS_INC} ../nan)# give library file a .node extension without any "lib" prefix
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")# essential include files to build a node addon,
# should add this line in every CMake.js based project
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC})# essential library files to link to a node addon
# add this line to every CMake.js based project
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB}) ```