CircleCI: Use nodejs version 12

Viewed 1887

My CircleCI file is provided:

version: 2.1
orbs:
  node: circleci/node@4.1.0
  aws-cli: circleci/aws-cli@2.0.3
  eb: circleci/aws-elastic-beanstalk@2.0.1
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?

2 Answers

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.

I think the issue was with the orbs as after I update to the node: circleci/node@4.7.0, I had no issue with NodeJS installation and build the project.

This makes sense as the cI/CD pipeline not suppose to run the software and hence, the NodeJS version should be irrelevent.

Related