Once you have installed a package in node_modules, you can use it in your code.

Using unscoped packages in your projects

Node.js module

If you are creating a Node.js module, you can use a package in your module by passing it as an argument to the require function.

package.json file

In package.json, list the package under dependencies. You can optionally include a semantic version.

Using scoped packages in your projects

To use a scoped package, simply include the scope wherever you use the package name.

Node.js module

package.json file

In package.json:

Resolving "Cannot find module" errors

If you have not properly installed a package, you will receive an error when you try to use it in your code. For example, if you reference the lodash package without installing it, you would see the following error:

  • For scoped packages, run npm install <@scope/package_name>
  • For unscoped packages, run npm install <package_name>
Edit this page on GitHub
3 contributorslukekarryslukekarryshuzejrovicahuzejrovicaethomsonethomson
Last edited by lukekarrys on October 23, 2023