Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Installing and Using External Packages | System Modules and Package Management
Working with Modules and Packages in Node.js

bookInstalling and Using External Packages

When you want to add features to your Node.js project, you often turn to external packages. These packages provide reusable code published by other developers, and you manage them using the Node Package Manager (npm). The most common commands for handling packages are npm install, npm uninstall, and npm update.

To add an external package, you use npm install <package-name>. This downloads the package from the npm registry and adds it to your project's node_modules directory. The dependency is also listed in your package.json file so others know which packages your project needs.

Removing a package is just as simple. Use npm uninstall <package-name>, and npm will delete it from your project and remove its entry from package.json. If you need to update a package to its latest version, run npm update <package-name>. This command checks for newer versions and installs them, keeping your project dependencies current.

npm manages dependencies by maintaining a list in your package.json file. This ensures that everyone working on your project can install the exact packages you use by running npm install. npm also creates a package-lock.json file to record the exact version of each installed package, ensuring consistent installs across different environments.

1234
// After running: npm install chalk const chalk = require('chalk'); console.log(chalk.green('Success! Your package is working.'));
copy
question-icon

Fill in the blanks to install the lodash package and use it in a Node.js script:

npm lodash const lodash = ('lodash');

Click or drag`n`drop items and fill in the blanks

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 3. Kapitel 3

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Awesome!

Completion rate improved to 7.14

bookInstalling and Using External Packages

Swipe um das Menü anzuzeigen

When you want to add features to your Node.js project, you often turn to external packages. These packages provide reusable code published by other developers, and you manage them using the Node Package Manager (npm). The most common commands for handling packages are npm install, npm uninstall, and npm update.

To add an external package, you use npm install <package-name>. This downloads the package from the npm registry and adds it to your project's node_modules directory. The dependency is also listed in your package.json file so others know which packages your project needs.

Removing a package is just as simple. Use npm uninstall <package-name>, and npm will delete it from your project and remove its entry from package.json. If you need to update a package to its latest version, run npm update <package-name>. This command checks for newer versions and installs them, keeping your project dependencies current.

npm manages dependencies by maintaining a list in your package.json file. This ensures that everyone working on your project can install the exact packages you use by running npm install. npm also creates a package-lock.json file to record the exact version of each installed package, ensuring consistent installs across different environments.

1234
// After running: npm install chalk const chalk = require('chalk'); console.log(chalk.green('Success! Your package is working.'));
copy
question-icon

Fill in the blanks to install the lodash package and use it in a Node.js script:

npm lodash const lodash = ('lodash');

Click or drag`n`drop items and fill in the blanks

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 3. Kapitel 3
some-alt