Node Package Manager (NPM), A Beginner Guide

Node Package Manager (NPM), A Beginner Guide

NPM is a package manager for JavaScript. It is very helpful for JS developers when it comes to sharing code, reusing, and updating the shared code. To install it, you have to install Node.js because it comes with Node.js (It is bundled with Node.js) To check if it is already installed, you can type npm -v in the command line. This will show a version if NodeJs is installed or an error if it is not installed.

After installing NPM, you need to open the project folder where you have to press left shift and then right-click on the mouse, PowerShell will be opened (in the case of windows). To create a package.json file, type npm init . Then, it will ask for some information like Name, version, Description, Entry point, Test Command, Git Repo, Keywords, License.

Do not worry, I am gonna give brief information about everything mentioned above.

Package Name is very important if you want to publish your package to other developers.

Two Important Naming Rules:

1- Length of Name < 214 Characters

2- No dot, underscore ( _ ) at start

Version: What version you are going to use?

Description: A small detail about what your package is all about.

Entry Point: Main Logic file where execution starts like (index.js)

Test Command: If you have some test tool, then mention the name of that test tool here.

Git Repo: Address of Git Repository

Keywords: Some keywords that tell about your Package so other developers can search it.

License: License name telling can other use it or not...

Let's talk about NPM CONFIGURATION now:

npm config list -l , This command will give you lists of keys (author name etc ...) Which you can modify/delete/set their values. Example, You want to set an author name that you haven't set while Initializing the dot JSON file. Then the first type npm config list -l and then find what is the key for the author name (key means what is the way to access author name), it is init-author-name. So, to sets its value, type npm config set init-author-name "Hammad". General Syntax is npm config set Key Value. The same goes for editing but when you have to delete, you do not have to give value. Just type npm config delete which is init-author-name in this case.

Will be talking about dependencies and Dev dependencies in the next blog soon. Stay Tuned!

Β