Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn 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

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 3

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

What is the purpose of the `chalk` package in this example?

Can you explain what the `package-lock.json` file does?

How do I know which packages are currently installed in my project?

Awesome!

Completion rate improved to 7.14

bookInstalling and Using External Packages

Swipe to show menu

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

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 3
some-alt