Understanding The Basics Of Npm Scripts New
NPM ( Node Package Manager ) is mainly used for two things: First and foremost, it is an online repository for the publishing of open-source Node. js projects; Second, it is a command-line utility for interacting with a said repository that aids in package installation, version management, and dependency management.
We use scripts to automate repetitive tasks. For example, building your project, minifying Cascading Style Sheets (CSS), and JavaScript (JS) files. Scripts are also used in deleting temporary files and folders, etc.
Some useful feature
- Pre-installed with Node
- Easy install packages/modules on your system
- Modules are basically javascript libraries
- Make it easy for developers to share and reuse code
If you want to use NPM you have to have node js installed. It’s preinstalled with node js.
Let’s first understand what is a package manager with an example
Consider you were building your own website and you need some special feature (Eg: animated vertical carousel) in it and you build that by your self then you think the functionality you build will help others also, so you decide to make it available to everyone by publishing it to sites like npm. Now other developers who are in need of that functionality can use your code by merely downloading that code from the npm. Suppose in the future you added some extra functionality to your carousel, with npm other developers who are using your code can easily get those updates.
The functionality that you build is called package or module and package manager is nothing tool or software that manages all the packages is called a package manager. In simple words, packages are pice of reusable code.
Every package has a package.json file that contains all the metadata of that package such as name, author, scripts, dependencies required for that project, etc. we can manually create a package.json file or we can run a command (npm init
)to create that file for us.
Run the below commands in the terminal (or) cmd prompt.
To Get Version
npm --version
or
npm -v
To Get Help
npm help
To set default value in package.json file
npm config set init-author-name "your-name"
you can set a default value for all the values in the package.json file with the above command ( Eg: init-license ).
To Uninstall Package
Uninstall Local Package
npm uninstall package-name
will uninstall the package.