How to do npm install just once in pipeline CircleCI

Viewed 210

I have built a pipeline with four steps: build, test, lint and deploy. However, I have to run npm install in three individual steps which I think could be done in a cleaner way. Could someone point me to how I could maybe do npm install globally instead?

This is the config.yml file:

version: 2.1

orbs:
  node: circleci/node@4.1.0
  heroku: circleci/heroku@0.0.10
  eslint: arrai/eslint@2.0.0

jobs:
  build:
    executor:
      name: node/default
    steps:
    - checkout
    - run: npm install
  test:
    executor:
      name: node/default
    steps:
    - checkout
    - run: npm install
    - run: npm run test
  lint:
    executor:
      name: node/default
    steps:
      - checkout
      - run: npm install
      - run: npm run lint
  deploy:
    executor:
      name: heroku/default
    steps:
      - checkout
      - heroku/deploy-via-git

workflows:
  main:
    jobs:
      - build
      - test:
          requires:
            - build
      - lint:
          requires:
            - test
      - deploy:
          requires:
            - lint
1 Answers
Related