Applications built with Node.js framework are scalable and this is due to its asynchronous nature. What does this mean? For example, imagine that, in a restaurant, the waiter takes your order and brings it to the kitchen, then continues to the next table while the chef prepares the food for the first table, so you can serve multiple tables while they prepare the food. . food from others, this is what is called asynchrony.
On the official Node.Js documentation they explain what NPM is, saying “npm is two things: first and foremost, it's an online repository for publishing open-source Node.js projects; second, it is a command-line utility to interact with a said repository that helps in package installation, version management, and dependency management”.
A large number of Node.js libraries and applications are published on npm, with many more being added every day. These applications can be found at https://www.npmjs.com/. Once you have a package you want to install, you can install it with a single command line command.
When you install Node.js, you get the npm CLI, which you can use to manage the packages in your application. Both can be updated separately and we will explain how.
Clear the npm cache
When installing some dependencies, you should make sure to clear the NPM cache first.
npm install -g n
This package will take care of handling the Node version in the root.
Install a new version of Node.js
n lts n latest
These two command lines will take care of installing the latest version of Node and its long-term support.
Uninstall previously installed versions
Entering this command removes previous versions and leaves only the latest installed:
NVM stands for Node Version Manager and is what will help you manage your Node. With this, you can install and specify the version of Node that each project uses. NVM allows you to test projects using different versions of Node.
When you have NVM installed, add this package:
nvm install [version]
You can install the latest version of Node like this:
nvm install node
And with this command, uninstall the other versions:
nvm uninstall [version]
When you have multiple versions installed, you may want to specify the version you want to use at any given time, one way to do this is by setting a default alias, for example:
nvm alias default [version]
In this way, when running Node it will be with that specific version that your project needs.
You can also get the latest version of Node directly from its website, where you can find long-term support for your device. Also, you can download the latest version of NPM.
Just as you use it to manage packages, with the same npm you can update it too, just by typing this command:
npm install -g npm@latest
With this command ready you install the latest global version of NPM on your device. If you have a Mac, you may want to pass the sudo command before the npm command, to install it to the root of your device.
Node.js should not be used for CPU-intensive applications, for example for video encoding. In this type of application, many calculations must be carried out through the CPU, and few operations touch the file system or the network.
Since Node applications are single-threaded, when they perform computations to serve one client, the others have to wait, and therefore should not be used for applications that are CPU intensive or where multiple computations need to be performed.