External package and Package.json
What is an External Package?
An external package is a package we install from a third party (someone else wrote it).
We use it to add extra functionality to our project without writing everything ourselves.
Example:
nodemon
— a package that automatically restarts the server when code changes.
Without this, we would have to stop and start the server manually after every change.
How to Install an External Package
Example: Install the colors
package from https://www.npmjs.com/package/colors
Open the terminal and run:
or
Example of Using an External Package
To run this code, type in the terminal:
What is package.json
?
package.json
is a file that contains details about your project, such as:
- Project name
- Project version
- External packages used (dependencies)
- Project description
- Author
- License
What is package-lock.json
?
package-lock.json
is a file that contains detailed information about the exact versions of every installed package and its dependencies (internal packages).
It ensures that everyone working on the project installs the same package versions.
What is node_modules
?
node_modules
is a folder where all installed external packages are stored.
How to Create a package.json
File
Run this command in the terminal:
You will be asked to fill in some details:
Important Notes
- External packages are stored inside the
node_modules
folder. - You should not push
node_modules
to GitHub — because it is a very large folder. - Other developers can easily install the required packages by running:
This will read package.json
and package-lock.json
and install everything needed.