3

I am new to NPM and I have a beginner question. I was going through an article and came across the following of what the author has to say:

Instead of doing:

$ cd /path/to/the/project
$ npm install mongoose
$ npm install express
$ npm install jade

Create a package.json file in the root of your app dir.

$ cd /path/to/the/project
$ touch package.json

package.json:

{
    "name": "your app name"
  , "version": "0.0.1"
  , "private": true
  , "dependencies": {
      "express": ">=2.5.0"
    , "jade": ">= 0.16.4"
    , "mongoose": ">=2.3.10"
  }
}

Then type in the following command all your packages will be installed.

$ npm install -l

Difficulty

Now I really like the idea of doing the following:

{
    "name": "your app name"
  , "version": "0.0.1"
  , "private": true
  , "dependencies": {
      "express": ">=2.5.0"
    , "jade": ">= 0.16.4"
    , "mongoose": ">=2.3.10"
  }
}

But what if instead of saying ">=2.5.0", I want it it be the latest version ? I.E. I want the same version as when I would go to the Git directory and press the download button. secondly, how do I know the specific name of the package on npm. Eg if I check the slider plugin here, I see the command to install it is:

npm install slider

So does that mean that if I was installing the above plugin using package.json, my package.json would look like below:

{
        "name": "your app name"
      , "version": "0.0.1"
      , "private": true
      , "dependencies": {
          "slider": "whatever"  // is this correct ??
      }
    }

My questions are:

  • how do I get the latest current stable version of a jQuery plugin
  • how do I get the naming right for the package.json file.
halfer
  • 19,824
  • 17
  • 99
  • 186
Alexander Solonik
  • 9,838
  • 18
  • 76
  • 174

2 Answers2

3

Simply use * as version, like this:

{
    "name": "your app name"
  , "version": "0.0.1"
  , "private": true
  , "dependencies": {
      "slider": "*"
  }
}

Edit: As noted in the comments, this is not a very good idea, it is better to state dependencies as "^1.2.3" (will match 1.x) or even better - "~1.2.3" (will match 1.2.x).

  • 1
    Using "*" (or ">=0.0.0") is generally not a good idea because if the library introduces incompatible changes, your project might break. – Jan Tojnar Feb 27 '16 at 12:31
  • @JanTojnar ok ! i agree with what your saying ... so in that case what if i want to find what is the latest version of waypoints ? https://www.npmjs.com/package/waypoints .. how do i find whats the latest version of a plugin, wihtout going to "google" and navigating to the projects git repo.. – Alexander Solonik Feb 27 '16 at 12:57
  • If you are adding a new dependency use `npm install package --save`, if you just want to update already installed libraries, look into `npm outdated`. – Jan Tojnar Feb 27 '16 at 13:00
  • @JanTojnar npm install package --save will save the current version ... what i want is suppose i want to install a plugin waypoints.js before i even do `npm install package --save` , i'd like to know whats the lastes version .. how do i find that out from the CMD ?? – Alexander Solonik Feb 27 '16 at 13:08
  • 1
    @Alexander Solonik There is [`npm info package`](https://docs.npmjs.com/cli/view) – Jan Tojnar Feb 27 '16 at 13:10
  • @JanTojnar superb , add that as a note in your answer :) – Alexander Solonik Feb 27 '16 at 13:12
  • @Alexander Solonik However `npm install package --save` already does install the latest version in addition to adding it to the `package.json` – Jan Tojnar Feb 27 '16 at 13:13
  • So `npm info` should not be needed when installing a new dependency nor when updating the old ones. – Jan Tojnar Feb 27 '16 at 13:23
3

Yes, the name after the npm install (or in the URL) is the same as one used in the package.json.

If you want to find the latest versions of packages you have installed, you can use npm outdated which will list the latest versions of outdated libraries. Then, you can update the package.json manually or use npm-check-updates.

If you are installing a new dependency, you can use npm install package --save which will install the latest version of the package and add it to your package.json automatically.

Community
  • 1
  • 1
Jan Tojnar
  • 5,306
  • 3
  • 29
  • 49