Skip to content
The Chat Archive
gpt-4o-mini-2024-07-18· OpenAI WildChat-4.8M (AI2)

npm command

  1. User

    npm command

  2. Assistant

    npm, which stands for Node Package Manager, is a command-line tool used to manage packages in Node.js and JavaScript projects. Here are some common npm commands:

    1. Initialize a new project:

      npm init
      

      This command will create a package.json file in your project directory. You can use npm init -y to skip the configuration questions and create a default package.json.

    2. Install a package:

      npm install <package-name>
      

      This installs the specified package and adds it to your node_modules directory. If you want to save it as a dependency in your package.json, you can use the --save flag (though this is the default behavior for npm 5 and above).

    3. Install a package globally:

      npm install -g <package-name>
      

      This installs the package globally on your system, allowing you to use it from anywhere in your terminal.

    4. Uninstall a package:

      npm uninstall <package-name>
      

      This removes the specified package from your project.

    5. Update a package:

      npm update <package-name>
      
    6. List installed packages:

      npm list
      

      This shows the currently installed packages in the local project. You can add -g to list global packages (npm list -g).

    7. Check for outdated packages:

      npm outdated
      
    8. Run a script defined in package.json:

      npm run <script-name>
      

      This is used to run a script defined in the "scripts" section of your package.json file.

    9. Install all dependencies:

      npm install
      

      This installs all the dependencies listed in your package.json.

    10. Update npm to the latest version:

      npm install -g npm
      

    These commands will help you manage your Node.js projects effectively using npm. If you're looking for a specific command or functionality, feel free to ask!