Set up Node.js with .nvmrc in GitHub Actions


Set an output parameter for .nvmrc:

steps:
  - run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc)
    id: nvm

Evaluate the expression in setup-node:

steps:
  # ...
  - uses: actions/setup-node@v2
    with:
      node-version: ${{ steps.nvm.outputs.NODE_VERSION }}

Here’s the full example of setting up Node.js with the .nvmrc version in a GitHub Actions workflow:

# .github/workflows/nodejs.yml
on: push
jobs:
  nodejs:
    runs-on: ubuntu-latest
    steps:
      - name: Read .nvmrc
        run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc)
        id: nvm
      - name: Use Node.js ${{ steps.nvm.outputs.NODE_VERSION }}
        uses: actions/setup-node@v2
        with:
          node-version: ${{ steps.nvm.outputs.NODE_VERSION }}

The original solution is from @damccorm’s comment. The updated solution is from @peaceiris’s comment. Credit goes to them.



Please support this site and join our Discord!