Home Forums Chapter 1: What is Express? Updating package.json with npm

This topic contains 0 replies, has 1 voice, and was last updated by  Yaapa 1 year, 9 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #63

    Yaapa
    Keymaster

    I had written in the book “Any time you install a Node module in the application directory, the module will get added to the dependencies list with the version you specified. Of course, you can manually make new entries or update the version numbers of existing dependencies if you want to.”, it has changed since npm was updated.

    To automatically add the installed packages to the dependencies list in package.json, specify the --save option when you install the package. Here is an example:

    $ npm install stylus --save
    

    This will install the latest version of Stylus in the application directory and update package.json to reflect the change.

    Before:

    {
      "name": "application-name",
      "version": "0.0.1",
      "private": true,
      "scripts": {
        "start": "node app.js"
      },
      "dependencies": {
        "express": "3.3.4",
        "jade": "*"
      }
    }
    

    After:

    {
      "name": "application-name",
      "version": "0.0.1",
      "private": true,
      "scripts": {
        "start": "node app.js"
      },
      "dependencies": {
        "express": "3.3.4",
        "jade": "*",
        "stylus": "~0.36.1"
      }
    }
    

    In case you want to add the package to the devDependencies list instead of dependencies, use --save-dev instead of --save.

    So, if you want to make sure the packages you install in the app directory are automatically added to the package.json file, don’t forget to specify the --save option while installing them.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.