Is there a way to install node-sqlite3
for multiple platforms I am targeting in my app without running standalone build for just every target platform combination?
In my Node.js app I have a npm dependency node-sqlite3
(GitHub, npm), which contains different binaries (bindings) for different platforms.
My app is targeting different platforms, including Windows, Linux and macOS (both ia32 and x64) and modern Node versions: v6, v7 and v8. The app doesn't have any platform-specific behavior.
If I install the project's dependencies using npm install
, node-sqlite3
downloads binaries just for the current platform (let's say win32
, x64
, Node v7.10
).
I also have a Travis CI build configuration, which I use for Continuous Deployment as well as Continuous Integration. I chose Ubuntu Trusty as a host for executing builds.
As a part of a build process the app's dependencies are being installed by npm install
. Within deployment process, the built app with it's dependencies is being packaged (archived) and uploaded to a file hosting for further distribution.
node-sqlite3
is not installed for all target platforms I need, but just for a platform currently being used (for development or executing a build).
I could execute builds and deploy:
But that's looks like a big overhead. As I've already said, the app doesn't have any platform-specific behavior. And I trust node-sqlite3
's vendor tested it at all major platforms I am targeting.
The sqlite3 module is actively maintained and provides a rich set of features: Simple API for query execution. Parameters binding support. Control the query execution flow, supporting both serialized and parallel modes. Comprehensive debugging support.
To add dependencies and devDependencies to a package. json file from the command line, you can install them in the root directory of your package using the --save-prod flag for dependencies (the default behavior of npm install ) or the --save-dev flag for devDependencies.
Yes, but simply copying the content of node_modules should be enought, unless you install globally. Another way that may be simpler is to run npm install angular-cli on a connected system, and copy the content of node_modules to the offline computer.
Yes, in case with node-sqlite3
you do have such a capability.
It is possible because it's owner mapbox uses node-pre-gyp
(GitHub, npm) for distribution of node-sqlite3
.
After installing your app's dependencies with npm install
execute the following command at the root of your Node project for every target platform combination:
./node_modules/.bin/node-pre-gyp install
--directory=./node_modules/sqlite3
--target_platform={OS}
--target_arch={OS architecture}
--target={Node version}
(please note that line breaks here are just for clarity, you have to remove or escape them prior to execution)
As a result you would have required bindings in ./node_modules/sqlite3/lib/binding/
directory.
Here's the options' descriptions from the node-pre-gyp docs.
--directory: run the command in this directory
--target_platform=win32: Pass the target platform and override the host platform. Valid values are linux, darwin, win32, sunos, freebsd, openbsd, and aix.
--target_arch=ia32: Pass the target arch and override the host arch. Valid values are 'ia32','x64', or arm.
--target=0.10.25: Pass the target node or node-webkit version to compile against
If they exist, prebuilt binaries for chosen platform will be downloaded from a file storage (Amazon S3). Otherwise you have to build binaries by yourself.
A list of available binaries of node-sqlite3
is here.
A couple of examples for certain target platforms:
• Windows x86 and Node 6.10.0:
./node_modules/.bin/node-pre-gyp install --directory=./node_modules/sqlite3 --target_platform=win32 --target_arch=ia32 --target=6.10.0
• macOS x64 and Node 7.10.0:
./node_modules/.bin/node-pre-gyp install --directory=./node_modules/sqlite3 --target_platform=darwin--target_arch=x64 --target=7.10.0
• Linux x64 and Node 8.0.0:
./node_modules/.bin/node-pre-gyp install --directory=./node_modules/sqlite3 --target_platform=linux--target_arch=x64 --target=8.0.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With