Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Update published npm packages using np

    Trevor MillerTrevor Miller

    When we want to update our package we need to do a few things: pull latest from our git remote, bump the npm version and git tag, push to our remote, push tags to our remote, and then run npm publish. Phew, that’s a lot. In this lesson, we will set up a release script using the np package to simplify this process.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    Let's open up our package.json in our code editor. Let's create a new script. Let's call this the release script. Let's have it run the np package. Let's save and close this file, and let's install the np package, npm-install np. We'll save that to our development dependencies.

    Let's make a small change to our package. I'm going to go inside of my test. Let's change everywhere there is three asterisks to be four asterisks. We'll save that. Let's do the same thing in our source file.

    Let's go back to our terminal and run nmp-run release. It says, "Select semver-increment or specify new version." Let's make this a minor update. It says this is going to bump it from 1.0to 1.1. Is that good?

    Let's say, "Yes." It failed and said that we have a unclean working directory. It says that we need to commit or stash our changes first. I'm going to stage and commit my changes. Now, we can run nmp-run release again.

    Again, it says some minor increment. Yes. Now, it's running through the different checks to make sure everything's good to go. It will also run our tests, and bump our versions, and then publish and push the latest.

    Everything we've needed to do to update our package has been done, and our new package version has been published. Our Git repo now shows a new tag for our new version, and our npm page for the package now has the latest version, as well.