NVM and NodeJS support programs with standalone setup on Windows - node.js

This might be an odd problem, but I find it troubling since NVM is so much better solution than a standalone NodeJS installation which includes only one version of node.
Since NodeJS no longer requires Python 2.7 to build native modules on Windows, it has become increasingly hard to set up everything on a clean installation of Windows for projects that compile modules from source, unless we use installer from NodeJS site (NodeJS 14.20.0 has it), which includes all of that. For example node module ttf2woff2 is one of those special modules.
If I try to set up everything initially with NVM those support programs are not installed and module compilation fails during installation.
Is there a way to download and install that bundle that includes all windows patches, compilers and the rest of support programs, without requiring me to install official NodeJS, and then just proceed to install all Node versions through NVM, which I use for my projects?

Related

Why does installing modules from NPM or Yarn depend on node?

I am using React (create-react-app)
My understanding of what happens when we install a package from NPM or Yarn is: It finds the module and clones the code into node_modules, modules can also have their own package.json and dependent modules are cloned recursively.
If we are using a purely client side app (like React in my case), why does install process depend on node version? Like I get jsdom#16.2.0: The engine "node" is incompatible with this module. Expected version ">=10". Got "9.11.2"
As newer versions of Node.js are released, new features are added and older features are deprecated. Libraries using these new features can decide to lock in the minimum Node.js version needed to use their library.
If you use the library with a lower version of Node.js, the library will probably not work.
If you're working on multiple projects that require different versions of Node.js, consider installing and using nvm. With nvm, you can switch between multiple versions as needed by your projects.
https://github.com/nvm-sh/nvm

Co-Existience of two different NodeJS for same project

I am quite new to NodeJS and am planning to upgrade NodeJS version for my current project. The most recent NodeJS LTS is installed using NVM.
I need to keep switching between the current LTS that i am using and the new LTS that has been installed. I understand that i can do 'NVM use' for this purpose. npm-shrinkwrap.json is being used to lock down the npm package dependencies.
I am planning to follow the below approach both in my dev machine and build machine;
Is it okay? If not, please suggest a best approach.
nvm use latest_LTS
Update the package.json to pick the version which is supported by
latest_LTS
npm install
generate testing_build
Whenever i need to generate a build for current release (with the previous LTS NodeJS)
nvm use currently_used_LTS
clear the node modules
npm install (Release npm-shrinkwrap.json)
generate release_build
Thanks
In theory that should work.
However have you considered the option of just doing a point release for the current release_build that does nothing except version-bump node?
You may find (after re-running your tests) that the latest version of node is backwards compatable with release_build (or only requires minor fixes), and you can simplify your life by porting everything to the latest node version, rather than constantly switching

How can I install node.js without putting it in the path?

I have an older node.js installed on my mac, that is still needed, but for some other application a newer version is needed as well that I would like to access using full path, so that the node command uses the older version.
So is there a way to compile from source or install node.js without modifying the PATH?
PS.: newer npm is needed for the newer node.js
The nvm (node version manager) package is designed to allow you using multiple node versions without modifying the system PATH.
You even can specify the required node version per project directory.

How to compile lesscss using node.js

Hi,
I have finished to code my website using lesscss client side and now want to compile less so I have donwloaded node.js. My website is running on localhost and I want first to know:
where I have to install node.js
what I have to do next ( commands lines tools, commands lines etc. ).
If someone can help me because I'm a newbie in this field.
Thanks.
You can install the LESS compiler directly from npm.
Install node.js. Go to this page and download the installer for your platform.
If you're on Windows, download the .msi; if you are on OSX, download the .pkg file. Whenever possible, download the 64-bit version (unless your system is running only 32-bit hardware and software). If you are on Linux and you want to use package managers, see this page.
Once you have node.js installed, you should also have npm, which is node.js Package Manager. You can open a terminal/console and run npm -v to make sure everything is installed correctly.
Eventually, you can install the LESS compiler by simply executing:
npm install -g less
(note: on OSX and Linux you may need to run this with sudo: sudo npm install -g less).
The LESS compiler will then be available as the lessc command. See examples here.
PS: Some GUIs also exist for simplifying working with lessc. Google "less gui windows/mac/linux" to see many results, like this one for Mac.
it's not mentioned what to do after installing node.js and installing less compiler on your node.
Go to your folder where you are hosting your project locally and then type styles. less styles.css. This should initiate the conversion from less to CSS at the node command prompt.

Where does node.js put its files?

I have recently started playing with node.js, but I got lost in a big mess of different versions of node, npm, nvm and other packages. I don't know what is installed globally and what is installed locally (and if locally, how do the packages know which versions of node they can use?).
I'd like to have some summary of what different installation options do. In specific:
Where is node installed when I use nvm, apt-get, make install or when using other ways?
Is it a good idea to install node locally?
Why does nvm change my ~/.profile instead of installing itself in some system-recognizable bin folder?
I saw that nvm can install different versions of node alongside each other - why would I want to do this? I can install them locally instead, right?
Where does npm install packages? I saw that it checks packages aganist version of Node, what happens to these packages when node is upgraded?
In what cases it is better to use global or local installation? Where should I put my packages then (and where they put by default?)
What's the difference between npm, nvm and nave?
EDIT: There is a lot of ways to install node here, this makes me even more confused...
Where is node installed when I use nvm, apt-get, make install or when
using other ways?
apt-get installs all the software, not only node, on the file system following the Ubuntu convention where to store binaries, man files, shared files, logs, etc. However, using apt-get you'll have only the certain version of node which is determined by the distribution release cycle. If there are updates available they will be installed with apt-get update; apt-get upgrade However, the newest version of some app won't be available until it makes its way into the distribution. For example node v0.x.y might not be available until Ubuntu 13.10 the only way to get will be to install it manually. The good side of apt-get or other system package manager is that it manages updates and package removal for you. It stores all the data about the software package in it's own database. You can always delete the node with apt-get remove node and that's it.
make install install the package manually, but it is considered harmful. Never use the make install mainly because you won't be able to delete the package easily, you'll have to read the Makefile and manually delete all the files installed by it. In a situation where you want to use make install there is always checkinstall available. It's a software which creates a native package and registers it with the system. When you decide to delete the package you could do this with one command instead of many. wiki link; Ubuntu guide on checkinstall
Now nvm script is a node version manager. It is very helpful and easy to use. It allows you to have multiple versions of node to be installed and used in parallel on your machine. It doesn't compile the node from source like make install so it is very fast. it doesn't depend on your distribution release cycle so you have access to all the node versions available at the moment. nvm downloads precompiled binaries and is perfect for general use. It stores it's node files in it's own folder locally so in case you want to compare something between the different node versions it's easy to do.
Is it a good idea to install node locally?
If by locally you mean using nvm then it's very good for development, and testing. Not sure about production performance implications and benefits between having it's installed from source or using the nvm precompiled binaries. I use nvm for development and installed from source in production. However if someone could explain this issue any further I'll be glad to learn more.
Why does nvm change my ~/.profile instead of installing itself in some system-recognizable bin folder?
Because nvm isn't an executable. It is a set of bash functions which are sourced by shell and could be used separately. You can invoke nvm_ls and nvm_ls_remote and others without the main script after is is sourced into your shell. What the main script does it parses the command line arguments and pretty prints the output in case of for example `nvm_ls_remote'.
in the ~/.profile the following line is added
[[ -s /home/USERNAME/.nvm/nvm.sh ]] && . /home/USERANME/.nvm/nvm.sh # This loads NVM
loads all the functions into your shell
I saw that nvm can install different versions of node alongside each other - why would I want to do this? I can install them locally instead, right?
You can install them locally using make install or checkinstall but you will have to make aliases for them like node_0.8.1, node_0.8.2, node_0.10.1 , etc. AND you'll have to manage new aliases, installing all the packages, removing them in case you don't need them YOURSELF. These are a tedious and boring tasks which could be error prone sometimes. nvm does all of these tasks for you for free.
You want to do this to test your app under the different versions of node. For example you are good and tested under the v0.8 but you want to use the new features of the v0.10.3 how do you do that ? You have to download the source code, compile, make an alias and run your app. you could do this with just nvm install 0.10.3 and run your app.
Sometimes you have to support more than one version of node. For example some hosted environments are not keeping in touch with the latest release and only have v0.6 Your clients which use your server app might encounter a bug specific to this version. When you fix the bug you have to reproduce it first. Using nvm installation of the v0.6 is one line and half a minute. And you can check all the versions you want this way easily. Test your code under different versions and make sure you are good to go.
Where does npm install packages? I saw that it checks packages aganist version of Node, what happens to these packages when node is upgraded?
If you are using nvm the packages which are installed globally with -g option are tied to the relevant node version. When you switch between versions with nvm use 0.x you have to either install the packages again or use nvm copy-packages <version> to use the packages from in the current version. If the packages are installed locally then it depends. package.json should contain info on the dependencies of the app. If it says node: '0.8' and you just updated to 0.9 you might encounter troubles. For example the behavior of process.nextTick was changed in the latest releases compared to 0.6. So be careful.
In what cases it is better to use global or local installation? Where should I put my packages then (and where they put by default?)
It depends. For development nvm is superior in my opinion. For me it is convenient and simple. For production there are might be some performance implications when using the precompiled binary files not optimized for your system. It would be better to ask this as a separate question so the people with the relevant experience could answer.
What's the difference between npm, nvm and nave?
npm is a node package manager -> link It contains userland packages developed by other people. These packages are not part of the node core. npm is used for publishing your code and dependency management. If your app requires other app developed by other people it is convenient to publish it via npm.
nvm is a node version manager it does a completely separate thing. It gives you an ability to very easily switch between node versions on the same machine and manages all he changes in your $PATH environment variable.
Consider nvm as update manager for the Operation System and npm as a manager of the applications for this system. Well, this comparison isn't precise but just came upon my mind
nave is basically the same as nvm but it is an executable whereas nvm is a script which is sourced into the shell. Each system has it's own benefits. You could make a separate question regarding it's use cases and differences.
My answer isn't 100% complete and contains a lot of subjective personal opinions. However, I hope I'll at least make some points more clear so you might proceed with other more specific questions. Btw, this question list of yours could be asked as separate questions. I believe stackoverflow gives best results when specific questions are asked separately and more people with relevant experience could contribute.
If you run
npm install
in folder with package.json, it installs all packages localy (in the current folder).
Also, npm default install packeges local. To install it globaly - use -g flag:
npm install -g <package>
Execute next command:
npm config list
You see all npm config description.
You can install modules in the local context of your application with
npm install modulename
In this case the module will be installed to your node_modules folder of your application.
Otherwise you can install a module in the global context with
npm install -g modulename
In this case the module will be installed for the hole system environment usually at /usr/local/bin/modulename.
The global installation makes sense for modules you need in more than one application, like express or node-inspector.

Resources