Once you have installed a package in node_modules
, you can use it in your code.
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 filevar lodash = require('lodash');
var output = lodash.without([1, 2, 3], 1);
console.log(output);
In package.json
, list the package under dependencies. You can optionally include a semantic version.
Using scoped packages in your projects{
"dependencies": {
"package_name": "^1.0.0"
}
}
To use a scoped package, simply include the scope wherever you use the package name.
Node.js modulepackage.json filevar projectName = require("@scope/package-name")
In package.json
:
Resolving "Cannot find module" errors{
"dependencies": {
"@scope/package_name": "^1.0.0"
}
}
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:
module.js:340
throw err;
^
Error: Cannot find module 'lodash'
npm install <@scope/package_name>
npm install <package_name>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4