DEV Community 👩‍💻👨‍💻

Alan Johnson
Alan Johnson

Posted on

Automate GitHub Actions Node Version

I use GitHub Actions for all my CI, and one annoying thing I hit early on was having to keep my GitHub Actions Node version in sync with the Node version I use for development.

To solve that issue I've switched to using Volta for Node version management. It's nice because it can switch Node versions on the fly based on what's configured in package.json, like this:


  "volta": {
    "node": "18.10.0"
Enter fullscreen mode Exit fullscreen mode

Then in GitHub Actions I use these couple of steps to load my Volta version of Node:

# set NODE_VERSION to be Volta's current version
- run: echo NODE_VERSION=$(jq -r .volta.node package.json) >> $GITHUB_ENV
- uses: actions/setup-node@v3
    node-version: ${{ env.NODE_VERSION }}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

We are hiring! Do you want to be our Senior Platform Engineer? We're hiring for a Senior Platform Engineer and would love for you to apply.

Head here to learn more about who we're looking for.