blink-so[bot] 817238ea64 refactor(nodejs): use base64 encoding and coder exp sync for pre/post install scripts
- Base64 encode pre/post install scripts to safely handle special characters
- Use separate coder_script resources for pre_install, install, and post_install
- Add coder exp sync want/start/complete for execution ordering
- Base64 encode the main install script (run.sh) via templatefile + base64encode
- Revert run.sh to original (no pre/post install handling)
- Add sync name outputs for cross-module dependency coordination
- Update README with cross-module coordination documentation
- Add output assertions to tests
2026-03-19 17:59:22 +00:00

2.7 KiB

display_name description icon maintainer_github verified tags
Node.js Install Node.js via nvm ../../../../.icons/node.svg TheZoker false
helper
nodejs

nodejs

Automatically installs Node.js via nvm. It can also install multiple versions of node and set a default version. If no options are specified, the latest version is installed.

module "nodejs" {
  count    = data.coder_workspace.me.start_count
  source   = "registry.coder.com/thezoker/nodejs/coder"
  version  = "1.1.0"
  agent_id = coder_agent.example.id
}

Install multiple versions

This installs multiple versions of Node.js:

module "nodejs" {
  count    = data.coder_workspace.me.start_count
  source   = "registry.coder.com/thezoker/nodejs/coder"
  version  = "1.1.0"
  agent_id = coder_agent.example.id
  node_versions = [
    "18",
    "20",
    "node"
  ]
  default_node_version = "20"
}

Pre and Post Install Scripts

Use pre_install_script and post_install_script to run custom scripts before and after Node.js installation.

module "nodejs" {
  count    = data.coder_workspace.me.start_count
  source   = "registry.coder.com/thezoker/nodejs/coder"
  version  = "1.1.0"
  agent_id = coder_agent.example.id

  pre_install_script  = "echo 'Setting up prerequisites...'"
  post_install_script = "npm install -g yarn pnpm"
}

Cross-Module Dependency Ordering

This module uses coder exp sync to coordinate execution ordering with other modules. It exposes the following outputs for use with coder exp sync want:

  • install_script_name — the sync name for the main Node.js installation script
  • pre_install_script_name — the sync name for the pre-install script
  • post_install_script_name — the sync name for the post-install script

For example, to ensure another module waits for Node.js to be fully installed:

module "nodejs" {
  count    = data.coder_workspace.me.start_count
  source   = "registry.coder.com/thezoker/nodejs/coder"
  version  = "1.1.0"
  agent_id = coder_agent.example.id
}

# In another module's coder_script, wait for Node.js installation:
# coder exp sync want my-script ${module.nodejs[0].install_script_name}

Full example

A example with all available options:

module "nodejs" {
  count              = data.coder_workspace.me.start_count
  source             = "registry.coder.com/thezoker/nodejs/coder"
  version            = "1.1.0"
  agent_id           = coder_agent.example.id
  nvm_version        = "v0.39.7"
  nvm_install_prefix = "/opt/nvm"
  node_versions = [
    "18",
    "20",
    "node"
  ]
  default_node_version = "20"
  pre_install_script   = "echo 'Pre-install setup'"
  post_install_script  = "npm install -g typescript"
}