Monday, 31 May 2021

package.json vs package-lock.json difference

 Package.json:

package.json is a file that contains information about your project (name, version, etc.) and it lists the packages that your project is dependent on.


So as you can see in the picture above after every dependency listed under package.json there's a number something like ^2.20.0 which is the version of that package but before the version, there is ^. So ^ (caret symbol) this little guy can be a total destroyer for your project.

^ sign before the version tells npm that if someone clones the project and runs npm install in the directory then install the latest minor version of the package in his node_modules.

So lets say I am having express with ^2.20.0 in package.json and then express team releases version 2.24.0 and now when someone clone my repo and runs npm install in that directory they will get the version 2.24.0 (You can also put ~ instead of ^ it will update to latest patch version)

However, this can be a huge issue if package developers break any of the functions on the minor version as it can make your application break down.

So npm later released a new file called package-lock.json to avoid such scenarios

package-lock.json:

package-lock.json will simply avoid this general behavior of installing updated minor version so when someone clones your repo and run npm install in their machine. NPM will look into package-lock.json and install exact versions of the package as the owner has installed so it will ignore the ^ and ~ from package.json.

Reference: https://medium.com/

Related Posts:

  • Understanding Rxjs Observable What is Reactive Programming? Reactive programming is programming with asynchronous data streams. Reactive Extensions for JavaScript (RxJS) is a rea… Read More
  • Routing - Angular What are the main routing Component? Angular provides 3 different components for routing configuration: Routes is the configuration to describe appl… Read More
  • Change detection in Angular What is change detection?The basic mechanism of the change detection is to perform checks against two states, one is the current state, the othe… Read More
  • Angular - Promises and Observables Promise Promises deal with one asynchronous event at a time. In Angular we can use either Promises or Observables. By default the Angular Http servic… Read More
  • Improve Performance of Angular appImprove Performance of Angular app1: Lazy loading moduleThe enterprise application built using angular contains many feature modules. All these m… Read More

0 comments:

Post a Comment

Topics

ADFS (1) ADO .Net (1) Ajax (1) Angular (47) Angular Js (15) ASP .Net (14) Authentication (4) Azure (3) Breeze.js (1) C# (55) CD (1) CI (2) CloudComputing (2) Coding (10) CQRS (1) CSS (2) Design_Pattern (7) DevOps (4) DI (3) Dotnet (10) DotnetCore (20) Entity Framework (5) ExpressJS (4) Html (4) IIS (1) Javascript (17) Jquery (8) jwtToken (4) Lamda (3) Linq (10) microservice (4) Mongodb (1) MVC (46) NodeJS (8) React (10) SDLC (1) Sql Server (32) SSIS (3) SSO (1) TypeScript (3) UI (1) UnitTest (2) WCF (14) Web Api (16) Web Service (1) XMl (1)

Dotnet Guru Archives