Server running on background gets canceled

I’m trying to execute a background server previously to execute a curl test for the node API. Here’s the config.yml file I’m using:

version: 2
jobs:
  build:
    docker:
      - image: circleci/node:7.10
      
    working_directory: ~/repo

    steps:
      - checkout
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "package.json" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      - run: npm install

      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}
      
      - run: 
          name: background server for tests
          command: npm start
          background: true
            
      - run: 
          name: test
          command: curl -i http://localhost:3010/api/public

But I keep receiving “step was canceled” on the “background server for tests” step. Can you please advice?

I think someone has mentioned that previously on this forum, and it was not certain that the process had actually stopped. Consider doing a new run step containing ps aux to see if it really has been backgrounded. I wonder if you might just be able to ignore this message.

Thanks, your sugestion was very useful, the process keeps running, all you have to do is add the sleep command to give the server a little time to be online.

1 Like