NPM Introduction, Package versions and updates in package.json

  • Post category:Node
  • Reading time:2 mins read

NPM stands for node package manager. There are millions of packages available on npm that we can use to develop our application.

Package versions and updates

The first thing we do when we start the project is to run the command npm init. It will create a package.json file, which is a kind of configuration file for our project. Now, type a package name, description of the project, and author, and then hit enter.

npm introduction

Now, the package.json file is created. We can see it in our project folder structure. Below is the package.json file configuration for my project.

{
  "name": "learning-node",
  "version": "1.0.0",
  "description": "\"node-js-tutorial\"",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "\"Abhishek Singh\"",
  "license": "ISC"
}

Now, let’s see how to install a npm package. I am installing slugify and to install this I have to run npm i slugify.

{
  "name": "learning-node",
  "version": "1.0.0",
  "description": "\"node-js-tutorial\"",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "\"Abhishek Singh\"",
  "license": "ISC",
  "dependencies": {
    "slugify": "^1.6.6"
  }
}

Now, in the dependencies, we can see that the package is installed. Let’s talk about the version numbers.

“slugify”: “^1.6.6”

^ symbol npm specifies by default. This symbol means it will automatically accept minor and patch releases but not major ones. The first number is called the major version, the second number is called the minor version, and the last one is called the patch version. The patch version is only intended to fix the bug.

If we use ~ in place of ^, that means we accept only patch changes.

If we want to update all of the versions automatically, then we can use * in place of ^. It will then accept the major version as well.

Deleting a package

npm uninstall <package-name>

Share this