Migrating node.js npm project from Windows to Linux - node.js

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?

Related

Nodejs node-gyp build for both windows and linux

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?

creating angular 8 project on windows 10 creates additional files

Up until a few days ago I have been using an Ubuntu virtual machine as my development environment for Angular and other related projects due to school, however I decided to switch over to windows since I already had node installed along with git and other development tools.
The issue I'm having is when I create an Angular 8 project using the ng new my-app command, additional files are being created in the root directory which never happened while I was using Ubuntu. The files that are being created are Command files (.cmd) and Powershell files (.ps1), along with files with no extension.
These are just some of the files that are created:
Angular 8 project files on windows
If I compare with the file structure of the projects created in Ubuntu (which are the typical angular.json, tslint, etc), I can delete the unnecessary files and the angular app still works. However, whenever I run npm install to reinstall the packages due to some error, these excess files are added again and I have to delete them every time.
I have tried uninstalling angular/cli and clearing cache using npm cache clean --force and installing angular/cli again but the problem persists. I have also tried removing node and installing it again to no avail.
I'm fairly new to angular and node.js, with only a few months experience from school projects, so I'm currently trying to learn more. I've tried searching using different terms but nobody seems to have encountered a similar problem. Any help is much appreciated.
These are the files that are found in the node_modules/.bin subfolder after npm install is done.
There is something wrong with your npm install. I would recommend uninstalling node, and making sure everything is removed (path variables, files in your user folder) and then reinstall it.

Install NodeJS package without npm

Question:
How to install NodeJS package (like grunt-cli) manually without using npm?
Environment:
I have installed Windows 10 with "Bash on Ubuntu on Windows".
I have successfully installed NodeJS + Grunt in the "normal" Windows environment without Bash.
NodeJS is installed in the bash environment (Linux-subsystem)
Grunt is not yet installed in the (Linux-subsystem)
Background (why):
My colleague's grunt tasks was developed for an Ubuntu environment and calls bash commands directly which obviously does not work in a "normal" Windows environment. This is an experiment to see if it is possible to run his grunt tasks in "Bash on Ubuntu on Windows" however, I am stuck on the part where npm tries to download the packages (network libraries are not yet supported by Linux-subsystem so commands like curl does not work).
I am hoping to "skip" the download part of npm by manually copying the downloaded version from the Windows environment (or GitHub) into the "node_modules" directory in the Linux-subsystem.
However, I do not know how to configure npm that there was a new package added and that it may use that package now.
You can copy all the packages you need with dependencies into node_modules directory and it will work fine.
I think the best way is install packages using npm on a "normal" computer. Then copy the node_modules directory on "normal" computer to your target directory.
Pre-built installer is now available in all platforms in the official website
https://nodejs.org/en/download/
You no need to install modules when node_module dir is available. If project is cloned from version control (GIT) Repository or node_modules folder is not available you should run below command
npm install
Otherwise you need to insert node_modules manually to your project.
you can also download node_modules from other computer and copy modules to your project
npm install --save <PACKAGE NAME>
Then you can find you dependency modules in your console folder.copy those files to your folder.

Is NPM dependent on the OS of a computer?

Is it possible to copy a set of NPM installed files and associated files from a Mac computer to a Windows computer, and for all those files to work?
For example, transfering Node.js files with some other NPM files from Mac to Windows, then running node app.js in that directory (on the Windows Command Prompt).
Thanks! :)
The binary, npm, that you install is platform dependent, as is node.js. That's why there are different releases for each platform available on the download site.
For the most part, your project files are platform independent. For example, most of your JavaScript files will all be used by node.js and work just fine without having to worry about what platform you are on because the system details will be dealt with by node.js itself.
However, some modules are platform dependent. For example, anything that uses node-gyp will try to compile on your platform whenever the module is installed by npm. You do not have to worry about that though because it is handled by npm, that's why you're using a package manager.
Copying node_modules can be done; but it's more often than not better and easier to just run npm i on whatever machine is going to be running your application. You can avoid having to worry about version problems using something like npm shrinkwrap which will lock down the version of a package that your module depends on.
NPM packages that contain native addons/dependencies are tied to the OS + NodeJS version and have to be rebuilt specifically for the system you intend to use them on. This is why you're seeing the error mentioning bson.node, it is a native addon that has to be rebuilt, this can be done with the npm rebuild command.

Nodejs/npm: How to reinstall/recompile copied app packages

Setup:
A VM with an Internet connection where npm install will be executed to install all the app dependencies. The result will be a folder with the app and its dependencies in node_modules.
Between the app modules is fi: mongoose, which on installation time uses node-gyp to compile a native BSON extension.
The app folder is copied to another VM without an Internet conection and it is fully functional, but then the compiled extensions don't work but its .js fallbacks does.
Question:
How can I reinstall/recompile/regenerate all the app modules on the new VM without an Internet conection?
This is precisely what the npm rebuild command does. Just run npm rebuild inside your app directory after it is copied over to the new VM and any binary add-ons will be recompiled to match the current CPU architecture and node version. If the initial npm install before the copy was completely successful, the npm rebuild on the second VM will not need to download anything. Just make sure the second VM has a reasonably-close version of node and the appropriate lower level compilers, libraries, etc (build-essential and python on debian, for example).

Resources