This is a super short post with a little semi-pro tip for working with npm packages and production quality builds and importantly: pinning releases.

[I’ve published 38 videos for new developers, designers, UX, UI, product owners and anyone who needs to conquer the command line today.](https://training.leftlogic.com/buy/terminal/cli2?coupon=BLOG\&utm_source=blog\&utm_medium=banner\&utm_campaign=remysharp-discount)

Context: technical post about node projects and npm

By default today, if you run npm install --save foo@1, you’ll get a new entry in your package as such:

  "dependencies": {
    "foo": "^1.1.0"
  }

Assuming(!) that the package author is following semver, then you’ll get all the fixes (patch) and features (minor) for free upon next install due to the leading ^ character (except in the cases like 0.1.0 or 0.0.1…​because "[semver](https://docs.npmjs.com/misc/semver#caret-ranges-123-025-004)" ¯_(ツ)_/¯ - but the point is, that it’s floating).

This might be fine for 3rd party dependencies, but might not work for your own packages. If this was my main application code, and foo was one of my own packages, I’d want to be sure I was installing exactly the version I intend to.

The npm cli has a little known (to me) command --save-exact (or -E) which will save the specific version. In addition, you can create an .npmrc file that’s in your project’s root directory that contains:

save-exact = true

This will mean that all npm install <pkg> commands will pin to the version that was available at the time you run the command.

Important note this does not guarantee being able to replicate the build. This is because the dependencies of your dependencies won’t be pinned. If you need this, then consider either using [shrinkwrap](https://docs.npmjs.com/cli/shrinkwrap) or [bundleDependencies](https://docs.npmjs.com/files/package.json#bundleddependencies).

Comments

Lock Thread

Login

Add Comment[M ↓   Markdown]()

[Upvotes]()[Newest]()[Oldest]()

coloured\_chalk

0 points

8 years ago

Also, you can shrinkwrap your deps to get same version installed everytime. This is useful for deployment

rem

0 points

8 years ago

Absolutely, and this is what I was hinting at right at the end of the post. Thanks for pointing out though.

[Commento](https://commento.io)