W3cubDocs

/Ansible 2.9

npm – Manage node.js packages with npm

Synopsis

  • Manage node.js packages with Node Package Manager (npm)

Requirements

The below requirements are needed on the host that executes this module.

  • npm installed in bin path (recommended /usr/local/bin)

Parameters

Parameter Choices/Defaults Comments
ci
boolean
added in 2.8
    Choices:
  • no
  • yes
Install packages based on package-lock file, same as running npm ci
executable
path
The executable location for npm.
This is useful if you are using a version manager, such as nvm
global
boolean
    Choices:
  • no
  • yes
Install the node.js library globally
ignore_scripts
boolean
    Choices:
  • no
  • yes
Use the --ignore-scripts flag when installing.
name
string
The name of a node.js library to install
path
path
The base path where to install the node.js libraries
production
boolean
    Choices:
  • no
  • yes
Install dependencies in production mode, excluding devDependencies
registry
string
The registry to install modules from.
state
string
    Choices:
  • present
  • absent
  • latest
The state of the node.js library
unsafe_perm
boolean
added in 2.8
    Choices:
  • no
  • yes
Use the --unsafe-perm flag when installing.
version
string
The version to be installed

Examples

- name: Install "coffee-script" node.js package.
  npm:
    name: coffee-script
    path: /app/location

- name: Install "coffee-script" node.js package on version 1.6.1.
  npm:
    name: coffee-script
    version: '1.6.1'
    path: /app/location

- name: Install "coffee-script" node.js package globally.
  npm:
    name: coffee-script
    global: yes

- name: Remove the globally package "coffee-script".
  npm:
    name: coffee-script
    global: yes
    state: absent

- name: Install "coffee-script" node.js package from custom registry.
  npm:
    name: coffee-script
    registry: 'http://registry.mysite.com'

- name: Install packages based on package.json.
  npm:
    path: /app/location

- name: Update packages based on package.json to their latest version.
  npm:
    path: /app/location
    state: latest

- name: Install packages based on package.json using the npm installed with nvm v0.10.1.
  npm:
    path: /app/location
    executable: /opt/nvm/v0.10.1/bin/npm
    state: present

Status

Authors

  • Chris Hoffman (@chrishoffman)

Hint

If you notice any issues in this documentation, you can edit this document to improve it.

© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.9/modules/npm_module.html