Managing node.js
Today most JavaScript libraries are developed, tested, and deployed or distributed via node.js framework. Many libraries stopped providing the regular js file for web developments. Instead, they are using modules, similar to Python. For legacy systems, a separate JS file is still needed and it is necessary to use node.js and npm to get the js file. This might be the only way to get the lasted version for some JS libraries.
The node.js
approach
Node.js
Version Management
NVM is supposedly the version management tool for node.js, although it is also quite straightforward to uninstall, install, or re-install a specific version of node.js. NVM, while offering much functionality and convenience, adds another layer of management. Other than managing node.js itself, much work is needed to manage all the packages (libraries/modules) in node.js. NPM is the internal tool from node.js for this.
node.js
package management
By default, node.js have a global module repository on a computer. For example, on Windows machine, it is at C:\Users\[user account]\AppData\Roaming\npm\node_modules\
folder. Or use npm root -g
to show the folder location. For consistency, it is recommended to use npm install -g [package name]
to install all packages to that global folder. When without using the -g
option, npm will install the package to a node_modules
folder at the current folder where the npm is running, which is called a local folder. By default, npm starts at C:\Users\[user account]
folder, so all the modules will be there if no directory was changed before running npm install
.
The conda
or mamba
approach
In addition to Python, Conda or mamba can manage environments for node.js and R as well.
conda create -n ndenv python=3.12.0 nodejs=20.12.2
This will create a new environment named ndenv with node.js installed. In the ndenv environment, the node_modules
serves as the global folder for all modules. For example, such a folder could be C:\conda\envs\ndenv\node_modules
. When activating this environment, all node.js tools will be available on the command line as those executable files are saved at the root folder of the environment. To truly make this node.js an isolated environment, always use the -g
option when install or update node.js modules or packages.
If a different version of node.js is needed, a new environment could be created for that specific version. But more conveniently, the regular conda updata -c conda-forge nodejs
will update it to the latest version available from the repository.
Currently, the latest version of node.js 22.5.1 installed through conda is missing some of the CLI tools and scripts for NPM. When running commands like npm outdated
or npm install -g leaflet,
errors will be reported. Using version 20.12.2, for example, can avoid these errors. More to be explored for the exact reason.
Downgrade command
conda install -c conda-forge nodejs=20.12
It seems node.js 22.9.0 or an ealier version on conda
and conda-forge
fixed this issue.