Can I run `npm` commands in subfolders?


#1

Hi, my repo structure is like this:

.circleci/config.yml
lab1/package.json
lab2/package.json
lab3/package.json

how can I configure circleci to enter in each lab folder and run npm install and npm test independent.


#2

May we see your config.yml file? I should think you could change directory and then run your commands, or indeed npm may have a path switch you can send to it.


#3

my config was like:

# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/node:9

    steps:
      - checkout

      - run: cd lab1
      - run: npm install
      - run: npm test

      # TODO: add caching to speed things up.

and it did not work, but found this config:

# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/node:9

    steps:
      - checkout

      # todo: find nicer solution than constantly "cd"ing to unit_testing
      - run: cd unit_testing && npm install

      - run: cd unit_testing && npm test

      # TODO: add caching to speed things up.

did not check it yet (because I deleted that repo), but can you have a look and give my a feedback about best practice.


#4

Lovely, that’s what I was going to suggest. By design, your run commands start off in your project root, so you will need to specify a directory change somehow (either via cd or an npm parameter, if it has such a thing).


#5

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.