Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript npm Basics (retiring) Updating and Uninstalling Packages with npm Updating Packages with npm

Jefferson Lessa
Jefferson Lessa
5,684 Points

How do I update a npm package to its lastest version?

I'm aware that you can use the '^' symbol to allow a package to accept minor updates, and a '~' symbol to accept patch updates. What do I do if I want to accept major updates?

And is there a way of doing these things without changing my package.json file?

2 Answers

Roy Penrod
Roy Penrod
19,810 Points

That's because of the instructions in the package.json file.

If you're sure you want to upgrade to the newest version and you know it won't break your app, you can open the package.json file in a text editor.

Find the line under either "dependencies" or "devDependencies" that mentions the package you want to update. Look for the version info to the right of the colon. It probably looks something like:

"boo" : "2.0.1"

Add a "greater than or equal to" sign in front of the version # like this:

"boo" : ">=2.0.1"

The "greater than or equal to" sign in front of the version tells it to grab the newest version that's greater than or equal to 2.01.

There are other options you can use. Check out the npm documentation and look for the section on dependencies.

Roy Penrod
Roy Penrod
19,810 Points

You're welcome. Glad it helped.

Roy Penrod
Roy Penrod
19,810 Points

Go to the folder that contains the package.json file and run: npm update

Jefferson Lessa
Jefferson Lessa
5,684 Points

If i do that, it will only update the module to its lasted minor update. i.e., if my version is 2.3.0, it may update it to 2.5.0, but not to 3.0.0.