Create a Debian-Based NAPI-Rust Image and Container for Writing and Testing NAPI-Rust Addon Modules for Node.js Applications.
NAPI-Rust is similar but different from NAPI C/C++ (https://nodejs.org/api/n-api.html)
NAPI-Rust is based on Rust toolchain and does not use node-gyp.
See NAPI C/C++ example: https://github.com/MongoExpUser/Shale-Reservoir-DNN-and-Drilling-Rare-Events-Graph/blob/master/test_addon.cc
-
Clone the repo. The Repo contains the following files:
(1) Dockerfile
(2) Cargo.toml
(3) package.json
(4) index.js
(5) ./src/build.rs
(6) ./src/lib.rs
(7) ./src/main.rs
(8) ./src/utilities.rsModify the above files as needed, or can keep the original contents to test.
-
sudo docker build -t mongoexpuser/napi-rust-app:latest .
-
sudo docker run -itd --name running-napi-rust-app -v "$PWD":/home/myapp --workdir=/home/myapp --privileged --restart unless-stopped mongoexpuser/napi-rust-app:latest
-
INTERACT with container: start/restart, stop, shell into, and exit container instance, respectively:
sudo docker start running-napi-rust-app
sudo docker stop running-napi-rust-app
sudo docker exec -it running-napi-rust-app bash
exit -
RUN commands inside the Docker instance, to compile, re-compile, run node.js app and clean code artifacts, respectively:
sudo docker exec -it running-napi-rust-app npm run build
sudo docker exec -it running-napi-rust-app npm rebuild
sudo docker exec -it running-napi-rust-app node index.js
sudo docker exec -it running-napi-rust-app cargo clean -
sudo docker exec -it running-napi-rust-app node index.js
-
In addition, the repo contains miscellaneous sample Rust codes and steps on how to compile the codes to WASM (Web Assembly) file.
See the link below.
https://github.com/MongoExpUser/Debian-Based-NAPI-Rust-Addons/blob/main/wasm/sample.rs -
The repo also contains HTML file that uses the compiled WASM file on the Front-End (Browser).
See the link below.
https://github.com/MongoExpUser/Debian-Based-NAPI-Rust-Addons/blob/main/wasm/index.html
1 - https://github.com/napi-rs/napi-rs
2 - https://www.npmjs.com/package/@napi-rs/cli
Copyright © 2015 - present. MongoExpUser
Licensed under the MIT license.