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! :)
Node.js is officially supported on Linux, macOS and Microsoft Windows 8.1 and Server 2012 (and later), with tier 2 support for SmartOS and IBM AIX and experimental support for FreeBSD. OpenBSD also works, and LTS versions available for IBM i (AS/400).
npm is a tool you install on your computer. It's part of node, so install the LTS version of Node to get both the node and npm commands in your command line. It must be installed on every computer where you want to work on your project, so if you move your files around using a USB drive don't forget that part!
NPM stands for Node Package Manager, which is an application and repository for developing and sharing JavaScript code. This guide will help you install and update Node.js and NPM on a Windows system and other useful Node.js commands.
When you install an npm package using npm install <package-name> , you are installing it as a dependency. The package is automatically listed in the package.
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.
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