2016-09-22 12:43:57 +00:00
---
title: About the npm Resource
2018-02-16 00:28:15 +00:00
platform: os
2016-09-22 12:43:57 +00:00
---
# npm
2019-04-26 18:24:29 +00:00
Use the `npm` Chef InSpec audit resource to test if a global NPM package is installed. NPM is the the package manager for [Node.js packages](https://docs.npmjs.com), such as Bower and StatsD.
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
<br>
2016-09-22 12:43:57 +00:00
2018-08-09 12:34:49 +00:00
## Availability
### Installation
2019-04-26 18:24:29 +00:00
This resource is distributed along with Chef InSpec itself. You can use it automatically.
2018-08-09 12:34:49 +00:00
### Version
This resource first became available in v1.0.0 of InSpec.
2016-09-27 19:03:23 +00:00
## Syntax
2016-09-22 12:43:57 +00:00
A `npm` resource block declares a package and (optionally) a package version:
2016-11-20 01:37:24 +00:00
describe npm('npm_package_name') do
2016-09-22 12:43:57 +00:00
it { should be_installed }
end
where
* `('npm_package_name')` must specify an NPM package, such as `'bower'` or `'statsd'`
* `be_installed` is a valid matcher for this resource
2018-06-01 08:52:46 +00:00
You can also specify additional options:
describe npm('npm_package_name', path: '/path/to/project') do
it { should be_installed }
end
The `path` specifies a folder, that contains a `node_modules` subdirectory. It emulates running `npm` inside the specified folder. This way you can inspect local NPM installations as well as global ones.
2017-10-03 21:35:10 +00:00
<br>
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
## Examples
2016-09-22 12:43:57 +00:00
2019-04-26 18:24:29 +00:00
The following examples show how to use this Chef InSpec audit resource.
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
### Verify that bower is installed, with a specific version
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
describe npm('bower') do
it { should be_installed }
its('version') { should eq '1.4.1' }
end
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
### Verify that statsd is not installed
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
describe npm('statsd') do
it { should_not be_installed }
end
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
<br>
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
## Matchers
2016-09-22 12:43:57 +00:00
2018-02-16 03:07:18 +00:00
For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
### be_installed
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
The `be_installed` matcher tests if the named Gem package and package version (if specified) is installed:
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
it { should be_installed }
2016-09-22 12:43:57 +00:00
2016-09-27 19:03:23 +00:00
### version
2016-09-22 12:43:57 +00:00
The `version` matcher tests if the named package version is on the system:
its('version') { should eq '1.2.3' }