DEV Community


Week1: NPM & Package-lock.json

・2 min read

How to install npm

When you install nodejs you will get npm along with it

To check node and npm version

node -v
npm -v
Enter fullscreen mode Exit fullscreen mode
NPM stands for Node Package Manager
  • it is a package manager for Javascript

The uses of npm are

  • It is an online repository for the publishing of open-source Node.js projects

if you want to import the testing framework you can just install it by

npm install --save-dev jest
Enter fullscreen mode Exit fullscreen mode
  • It is a command-line utility for package installation, version management, and dependency management.

if you have module @jest/core, you can update to the latest version by

npm install @jest/core@latest
Enter fullscreen mode Exit fullscreen mode

Once you install the library, it will store in node_modules

Normally, node_modules gonna be a big folder, so you do not push it into git.

It is recommended to have package.json and package-lock.json, to help you know those libraries and their versions

To create a package.json file

npm init
Enter fullscreen mode Exit fullscreen mode

Package.json - list the version of its dependencies (library we install), and also other project information such as name, version, author, script, etc.

Package-lock.json - list solely about the dependencies in depth

Now when you want to install those libraries, npm can get the info from package-lock.json

To install dependencies just run:

npm install
Enter fullscreen mode Exit fullscreen mode

Also keep in mind that:

  • You can have only package.json
  • But you can not have only package-lock.json file

package-lock.json have to come with package.json

** And both files need to be stored in git


Discussion (0)