Node.Js Package Managers
Each Node.js application server on the platform comes with built-in support for two main package managers: Yarn and npm. Both use the same npm registry, which has many software packages, making it easy to install, update, configure, and remove them.
By default, the npm package manager is used for archive or Git deployment through the platform dashboard. However, you can switch to Yarn if needed. To do this, go to the Docker container settings and set the PACKAGE_MANAGER variable to either npm or yarn.
Here are some basics to help you choose between npm and Yarn:
Node Package Manager (npm)
Node Package Manager (npm) helps manage the extra modules and packages your project needs, as well as install ready-made applications.
You can install Node.js packages with npm in two ways:
- Using package.json: List the required packages in the dependencies section of the NodeJS package.json file located in your project’s root directory. These packages will be automatically downloaded and installed by npm when the application server starts. New modules listed in package.json will be added after restarting the NodeJS node.
- Using SSH: Connect to the container via SSH and manage your packages manually with these commands:
- npm search {package_name}: Search for modules by name.
- npm install {package_name}: Install a module.
- npm uninstall {package_name}: Remove an installed module.
- npm update {package_name}: Update a module to the latest version.
- npm ls installed: List installed packages.
Yarn Package Manager
Yarn is a fast, reliable, and convenient package manager that uses the same package.json file as npm, so you don’t need to change your existing applications.
To work with Yarn over SSH, use these commands:
- yarn or yarn install: Install all dependencies for the project.
- yarn remove {package}: Remove a specified package.
- yarn add {package}@{version}: Add a new package to the dependencies list and install it. You can specify a version; otherwise, the latest version will be used.
- yarn upgrade {package}@{version}: Update a package to its latest version or specify a version.
- yarn list: List all installed packages.