This example shows how to embed NodeJS into C/C++ source code. The instructions are focused on Linux but it can be ported to other platforms easily.
For building this example you need NodeJS to be installed in the system (10.x has been tested) and Python 2.7 available as python
command (due to NodeJS build system dependency). For debian based distros:
sudo apt-get install -y --no-install-recommends build-essential cmake ca-certificates git nodejs npm python2.7 node-gyp unzip
sudo npm install -g npm@latest
alias python=/usr/bin/python2.7
Build the project, MetaCall dependency may require root permissions in order to be installed in the system.
git clone https://github.com/metacall/embedding-nodejs-example.git
mkdir embedding-nodejs-example/build && cd embedding-nodejs-example/build
cmake ..
cmake --build . --target install
From project root directory, run the following commands:
export LOADER_LIBRARY_PATH="/usr/local/lib"
export LOADER_SCRIPT_PATH="`pwd`"
./embedding-nodejs-example
Building and running with Docker:
docker build --build-arg DISABLE_CACHE=`date +%s` -t metacall/embedding-nodejs-example .
docker run --rm -it metacall/embedding-nodejs-example