c-wrapper-nodejs-addon

This is start app setup to start writing c/c++ wrapper as node js add-on to use in nodejs. Aim of this project is to include all dependencies needed to use to write wrapper so that a user can just install it using traditional `npm start` command. And then


Keywords
C, wrapper, c++, addon, nodejs
License
ISC
Install
npm install c-wrapper-nodejs-addon@3.0.0

Documentation

C-WrapperNodeJSAddon

This package is to make easy sample to setup initial project to start writing C/C++ code wrapper as add-on to use in node JS. It will make easy to install all dependencies just with npm start.

Important note: BASS DLLs used in this project are added just for learning point of view. For Licenses, must contact corresponding forum. http://www.un4seen.com/

1. Prerequisites

nodejs version 8+ must be installed on your system and the below global node packages must be installed:

2. Cloning the repository

Clone the repository:

git clone https://github.com/muhammad-shahzad-anjum/C-WrapperNodeJSAddon.git

3. Installing dependencies

Install dependencies by running the following command: npm install c-wrapper-nodejs-addon (If it does not clone, then download or clone repo as below)

OR

  1. clone to https://github.com/muhammad-shahzad-anjum/C-WrapperNodeJSAddon.git
  2. Install Python 2.7 (v3.x.x is not supported), and run npm config set python python2.7 https://www.python.org/downloads/ Download and install version Python 2.7.14 If you have multiple Python versions installed, you can identify which Python version node-gyp uses by setting the '--python' variable: $ node-gyp --python /path/to/python2.7 If node-gyp is called by way of npm and you have multiple versions of Python installed, then you can set npm's 'python' config key to the appropriate value: $ npm config set python /path/to/executable/python2.7
  3. In console move to project root folder and run

npm install

4. Building the project

Build the project by running the following command: Generate the appropriate project build files for the current platform rebuild -Runs clean, configure and build all in a row

node-gyp rebuild

Command Description help -Shows the help dialog build -Invokes make/msbuild.exe and builds the native addon clean -Removes the build directory if it exists configure -Generates project build files for the current platform rebuild -Runs clean, configure and build all in a row install -Installs node header files for the given version list -Lists the currently installed node header versions remove -Removes the node header files for the given version

build directory will be created during the build

5. Starting the application

Start the application by running the following command:

npm start

The application will be displayed in the browser.

5. Test the application

npm test

The application will be displayed with the result of all test cases.

Resources

How to Create and Publish Your First Node.js Module https://medium.com/@jdaudier/how-to-create-and-publish-your-first-node-js-module-444e7585b738

Note: Update and publish changes in existing package After changing the version number in your package.json, you can run npm publish to publish the new version to NPM.

Node.js v8.7.0 Documentation - C++ Addons https://nodejs.org/api/addons.html

Node.js native addon build tool - node-gyp For wrapper it is must to install node-gyp and pythan https://github.com/nodejs/node-gyp#installation

Microsoft's windows-build-tools For wrapper it is must to install Install all the required tools and configurations using Microsoft's windows-build-tools using npm install --global --production windows-build-tools from an elevated PowerShell or CMD.exe (run as Administrator). https://github.com/nodejs/node-gyp#installation

Install Python 2.7 (v3.x.x is not supported), and run npm config set python python2.7 https://www.python.org/downloads/ Download and install version Python 2.7.14 If you have multiple Python versions installed, you can identify which Python version node-gyp uses by setting the '--python' variable: $ node-gyp --python /path/to/python2.7 If node-gyp is called by way of npm and you have multiple versions of Python installed, then you can set npm's 'python' config key to the appropriate value: $ npm config set python /path/to/executable/python2.7

C++ Wrapper links https://en.wikipedia.org/wiki/Dynamic-link_library#Using_DLL_imports https://stackoverflow.com/questions/10340552/how-to-pass-a-wrapped-c-object-to-a-javascript-callback https://stackoverflow.com/questions/38370023/how-to-add-a-method-to-functionalized-module-exports

BASS DLL download and Documentation http://www.un4seen.com/doc/#bass/BASS_GetVersion.html http://www.un4seen.com/

Node.js Foreign Function Interface - Not used in this project but helping material https://github.com/node-ffi/node-ffi