'CircleCI: Use nodejs version 12

My CircleCI file is provided:

version: 2.1
orbs:
  node: circleci/[email protected]
  aws-cli: circleci/[email protected]
  eb: circleci/[email protected]
jobs:
  build:
    docker:
      - image: "cimg/base:stable"
    steps:
      - node/install
      - checkout
      - aws-cli/setup
      - eb/setup
      - run:
          name: Check current version of node
          command: node -v
      - run:
          name: Get and install node version manager.
          command: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
      - run:
          name: Install Node version 12 using NVM
          command: nvm install 12 
      - run:
          name: Use Node version 12 
          command: nvm use 12     
      - run:
          name: Back-End Install
          command: |
            npm run backend:install
      - run:
          name: Front-End Install
          command: |
            npm run frontend:install
      - run:
          name: Back-End Build
          command: |
            npm run backend:build
      - run:
          name: Front-End Build
          command: |
            npm run frontend:build
      - run:
          name: Back-End Deploy
          command: |
            npm run backend:deploy
      - run:
          name: Front-End Deploy
          command: |
            npm run frontend:deploy

During the setup, the CircleCI install node version of v16.9.0 and I need to use v12. So, I run additional command to use v12 using NVM.

Is there easier way to use specific version of the Node during the time of setup?



Solution 1:[1]

Using cimg with node version as a docker image should work. You don't have to manually install using nvm.

jobs:
  build:
    docker:
      - image: cimg/node:12.16

https://hub.docker.com/r/cimg/node

I'm using cimg/node:16.13.2 and it works fine.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 foloinfo