Global Installation & Local Installation in React js
You've probably heard of NPM, NPX, NVM and Yarn if you deal with JavaScript. Almost certainly, you've used them to install something. In this piece, I'll explain what they are, as well as the differences between NPX, NPM, NVM, and Yarn as well as their benefits and drawbacks.
NPM:
When you install Node on your PC, you also install npm (which is included by default). NPM(Node Package Manager) is the package manager for the Node JavaScript platform. It puts modules in place so that node can find them, and manages dependency conflicts intelligently. Packages are updated as well, and npm makes it easy for us to stay on top of things. It allows us to. If we want to, we can upgrade the package, or we can utilise a different version if that's what we need.
npm is the world's largest Software Library (Registry), and it is also a software Package Manager and Installer for javascript projects.npm is widely used by nodejs, angular, react, vuejs frameworks, you can create your own package and publish the package to the marketplace. it is very helpful to share the code, plugin with other developers and the open-source community. npm has boosted the open source community to a new level.
How to install
To use the npm, you need to install the nodejs, npm is in-built with nodejs.
You can download the nodejs from the official site nodejs.org,
After downloading, please install it.
- For windows Install it in the c drive, and copy the installed location path
C:\Program Files\nodejs
and add it in your enviorement variables
How npm package works
After installing the nodejs, you can verify the installation by running the npm --version
command from your command runner.
What is package.json
package.json
file is used to maintain the all npm package with the version. this file contains all the npm packages you installed.
How to generate the package.json file
npm provides npm init
command to generate the package.json
file while running this command it will ask some details like - package name
: Name of the package you want to add like demo-app
version
: version by default 1.0.0description
: add descriptionentry point
: when you runnpm start
, the provided entry point will run, you can add index.js or leave blank ittest command
: Any script you want to use for testinggit repo path
: You can provide your GitHub repo URLkeywords
: For searching and SEO purposeauthor
: Add the name of the authorlicence
: Add like MIT or ISC
How to install the npm package
You can get the npm package you want to install from the NpmJS
You can install the package globally and locally
- A. Globally
Open Your DOS Command Prompt, there use this npm install -g create-react-app, then it will creates some files in your system as globally
- npm install -g create-react-app
- create-react-app appName
- B. Locally
List of npm common commands
Below is the list of all npm commands
npm init
: to generate the package.json filenpm i
ornpm install
: to install all packages of thepackage.json
filenpm i -g
: install the package globallynpm start
: It will execute the entry point script you added in thepackage.json
filenpm install npm@latest -g
: Upgrade the npm package to the latest versionnpm outdated
: list of all out date packagesnpm list -g
: list of all global npm packagesnpm uninstall "package name"
: it will uninstall the packagenpm publish
: This is used to publish the package at npmjs
YARN:
YARN(Yet Another Resource Negotiator) is a package manager similar to npm, but One of the main difference between NPM and Yarn is how they handle the package installation process. Yarn installs packages in parallel.
Yarn is optimized to fetch and install multiple packages simultaneously(yarn is faster than npm at installing packages).
Yarn Installation
NVM:
NVM(Node Version Manager) which stands for Node Version Manager, is to allow you to check the version of Node.JS you have installed and even to install a fresh, most up to date version of Node. It also allows you to install numerous instances of Node, allowing you to test your app in different versions of the programme to see if it works.
NPX:
The npx stands for Node Package Execute and is included with npm. If you install npm above version 5.2.0, npx will be installed as well.It's a npm package runner that allows you to run any package from the npm registry without having to install it. During a one-time usage package, the npx is useful. Npx is not installed in your computers if you have installed npm prior to 5.2.0.
Note:
The V8 Javascript runtime underpins Node.js. A Javascript engine is built into each browser, including Firefox, Safari, and Chrome, to handle Javascript files on webpages. The V8 engine is used by Google Chrome and Node.js to interpret Javascript files.
I hope this information will assist you in deciding whether to use Yarn, NPM, or NVM in your projects.