---
# System prepended metadata

title: Install nodejs and npm oneliner

---

# Install nodejs and npm oneliner

Without `sudo` or `root` privileges.

```

variable "node_version" {
  type        = string
  description = "NodeJS version to install on TF Cloud node to install Lambda dependencies"
  default     = "v14.15.0"
}

resource "null_resource" "install_deps" {
  triggers = {
    archive_hash = data.archive_file.test_for_changes.output_sha
    always_run   = timestamp()
  }

  # Install nodejs
  provisioner "local-exec" {
    command = "mkdir -p $HOME/.local/node; curl -L https://nodejs.org/dist/${var.node_version}/node-${var.node_version}-linux-x64.tar.xz | tar -xJ --strip-components=1 -C $HOME/.local/node"
  }

  # Install npm
  provisioner "local-exec" {
    command = "export PATH=$HOME/.local/node/bin:$PATH; curl -L https://www.npmjs.com/install.sh | sh"
  }
}
```