Nodejs node-gyp build for both windows and linux - node.js

I'm creating a nodejs App and packaging with pkg for both windows and linux, I'm using a windows pc and was wondering if there was a way to build a cpp file for both linux and windows using node-gyp on my windows pc.
I was thinking of building and packaging for windows then rebuild the project under an linux version of node but don't know how to do it?

Related

Unable to start Angular project on AWS Windows Machine (AMD)

I am trying to install and setup existing angular project on AWS windows machine.
The project was developed and was working on MAC OS earlier but now I have set it up on AWS windows machine and getting error while "ng serve".
Below are the versions -
Angular CLI: 14.2.6
Node: 18.14.0 (Unsupported)
Package Manager: npm 9.3.1
OS: win32 x64
NOTE: The code is still running fine on the mac os and linux environment but getting issue on windows (AMD processor).

Migrating node.js npm project from Windows to Linux

I am migrating a Node project that I developed locally on Windows to a remote Linux VM.
I've copied all the source .js files and package .json files to the Linux VM (not the node-modules directory), and when I run npm install, I am faced with many node-gyp ERR errors related to things like python, pkg-config, and other dependencies that I did not have to deal with when I created the project in Windows. I may have simply installed "windows-build-tools" locally on Windows.
Is there an equivalent for Linux? What is the correct strategy when migrating a Node project from one OS to another?

Cross-platform install of npm package sqlite3

Question
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?
Context
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.
Issue
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).
Possible solution
I could execute builds and deploy:
with Travis - for Linux and macOS
with AppVeyor - for Windows
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.
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}
As a result, you will have required bindings in the ./node_modules/sqlite3/lib/binding/ directory.
Options
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.
Examples
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

nodejs - using electron with ffi

i have nodejs x86 on windows 10 x64 and i installed electron with npm using this npm i -g electron and have a .dll file for driving external device.
i am using electron to develop desktop application.
i searched for finding a way for calling dll functions from js and i found ffi package. in first place i installed node x64 but i faced this error
App threw an error during load
Error: %1 is not a valid Win32 application.
then i searched it and i found this issue on github.
i uninstall my nodejs and replaced it with x86 version and this error still remain on my project. it seems that when i install ffi with npm npm i ffi, npm downloads source files and compile it with host architecture(x64) then ffi compile it self with my visual studio 2015 on x64 mode.
i even try to install ffi with npm i ffi --arch=ia32 but it did not work.
i donot have dll source files so i cannot rebuild it for any specific architecture.
How can i use electron 32bit version with ffi 32bit?
Is there any way to download ffi prebuild version and attaching it to project?
I want to use any version of electron (x64 and x86) and using my same 32bit dll.
The error typically happens when trying to load a 64-bit DLL from a 32-bit application.
In most cases, electron-rebuild should solve this issue for you, by rebuilding modules for the correct environment.

Exporting node-printer in Electron

I was able to get node-printer to work on my local machine for my electron app to print this certain pdf I have. The issue is that when I build and package the app and install it on a different machine, it doesn't work. Do these other machines also need to have those dependencies of python and VS2013 that I needed to install the module? If so what would be the alternative be since I don't want my users to have install python, VS2013, and node gyp just to make printing work?

Resources