DEV Community

nicha
nicha

Posted on

3 2

Week1: NPM & Package-lock.json

How to install npm

When you install nodejs you will get npm along with it
https://nodejs.org/en/download/

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

FOR EXAMPLE:
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.

FOR EXAMPLE:
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

Reference:
https://nodejs.org/en/knowledge/getting-started/npm/what-is-npm/
https://stackoverflow.com/questions/45052520/do-i-need-both-package-lock-json-and-package-json#:~:text=No.-,The%20package.,to%20a%20specific%20version%20number.

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay