Tired of constant dependency headaches every time you clone a project? I hit my breaking point just last month, and it was time to take control.

Here's a lightweight solution I put into place to avoid 90% of the chaos:

  1. Add a .nvmrc file to every project (trust me, it’s a game-changer).
  2. Include a simple setup.sh script that auto-installs dependencies.
  3. Feature this in your README for easy access!

I thought about automating this with Make.com, but I got lost in webhook madness 😂🥽.

However, GitHub Actions? Always a win. Here’s how I set it up:

Create a new workflow in .github/workflows/setup.yml with the following code:

name: Setup Node.js Environment

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  setup:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Create .nvmrc file
      run: |
        echo "v14.17.0" > .nvmrc

    - name: Setup Node.js with nvm
      uses: actions/setup-node@v3
      with:
        node-version-file: .nvmrc

    - name: Create setup.sh script
      run: |
        echo '#!/bin/bash' > setup.sh
        echo 'if [ -f .nvmrc ]; then' >> setup.sh
        echo '  nvm install' >> setup.sh
        echo '  nvm use' >> setup.sh
        echo 'fi' >> setup.sh
        echo 'npm install' >> setup.sh
        chmod +x setup.sh

    - name: Run setup.sh
      run: ./setup.sh

    - name: Update README.md
      run: |
        echo "## Setup Instructions" >> README.md
        echo "1. Ensure you have 'nvm' installed." >> README.md
        echo "2. Run 'nvm install' to install the Node version defined in .nvmrc." >> README.md
        echo "3. Run './setup.sh' to install dependencies." >> README.md
    - name: Commit updated README
      run: |
        git config --global user.name "GitHub Actions"
        git config --global user.email "[email protected]"
        git add README.md
        git commit -m "Updated README with setup instructions"
        git push

Boom – no more "which Node version?" debates. Clean, simple, and saves hours of frustration. 💡