Skip to content
check-square

GitHub Action

Read package.json node version

v2.0.0 Latest version

Read package.json node version

check-square

Read package.json node version

Output node version number from package.json engines field

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Read package.json node version

uses: culshaw/read-package-node-version-actions@v2.0.0

Learn more about this action in culshaw/read-package-node-version-actions

Choose a version

Read node version from engines field in package.json

Read your node version from package.json

Example workflow

package.json

{
  "name": "your-package",
  "engines": {
    "node": "12.13.x"
  }
}

.github/workflow/test.yml

name: Get node version from package.json

on: push

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v1

      - name: Read node from package.json
        uses: culshaw/read-package-node-version-actions@v1
        id: package-node-version

      - name: Show node version number
        run: echo "Version is ${{ steps.package-node-version.outputs.version }}"
        # Version is 12.13.x

Inputs

path

Path of package.json, ./ by default.

path/to/package.json

{
  "name": "your-package",
  "engines": {
    "node": "12.13.x"
  }
}
name: Get version from package.json

on: push

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v1

      - name: Read node from package.json
        uses: culshaw/read-package-node-version-actions@v1
        with: 
          path: "./path/to/package.json"
        id: package-node-version

      - name: Show version number
        run: echo "Version is ${{ steps.package-version.outputs.version }}"
        # Version is 12.13.x

License

MIT