Language Guide: JavaScript

Tutorials & 2.0 Sample Apps > Language Guide: JavaScript

If you’re new to CircleCI 2.0, we recommend reading our Project Walkthrough for a detailed explanation of our configuration using Python and Flask as an example.

Quickstart: demo JavaScript NodeJS reference project

We maintain a reference JavaScript NodeJS project to show how to build an Express.js app on CircleCI 2.0:

In the project you will find a CircleCI configuration file .circleci/config.yml. This file shows best practice for using CircleCI 2.0 with Node projects.

Pre-built CircleCI Docker images

We recommend using a CircleCI pre-built image that comes pre-installed with tools that are useful in a CI environment. You can select the Node version you need from Docker Hub: The demo project uses an official CircleCI image.

Database images for use as a secondary ‘service’ container are also available.

Build the demo JavaScript Node project yourself

A good way to start using CircleCI is to build a project yourself. Here’s how to build the demo project with your own account:

  1. Fork the project on GitHub to your own account
  2. Go to the Add Projects page in CircleCI and click the Build Project button next to the project you just forked
  3. To make changes you can edit the .circleci/config.yml file and make a commit. When you push a commit to GitHub, CircleCI will build and test the project.

Config Walkthrough

Following is the .circleci/config.yml file in the demo project with comments.

version: 2 # use CircleCI 2.0
jobs: # a collection of steps
  build: # runs not using Workflows must have a `build` job as entry point
    working_directory: ~/mern-starter # directory where steps will run
    docker: # run the steps with Docker
      - image: circleci/node:4.8.2 # ...with this image as the primary container; this is where all `steps` will run
      - image: mongo:3.4.4 # and this image as the secondary service container
    steps: # a collection of executable commands 
      - checkout # special step to check out source code to working directory
      - run:
          name: update-npm 
          command: 'sudo npm install -g npm@latest'
      - restore_cache: # special step to restore the dependency cache 
          key: dependency-cache-{{ checksum "package.json" }}
      - run:
          name: install-npm-wee
          command: npm install
      - save_cache: # special step to save the dependency cache
          key: dependency-cache-{{ checksum "package.json" }}
            - ./node_modules
      - run: # run tests
          name: test
          command: npm test
      - run: # run coverage report
          name: code-coverage
          command: './node_modules/.bin/nyc report --reporter=text-lcov'
      - store_artifacts: # special step to save test results as as artifact
          path: test-results.xml
          prefix: tests
      - store_artifacts:
          path: coverage
          prefix: coverage
      - store_test_results: # special step to upload test results for display in Test Summary
          path: test-results.xml
      # See for deploy examples    

Success! You just set up CircleCI 2.0 for a NodeJS app. Check out our project’s Job page to see how this looks when building on CircleCI.


See the Deploy document for example deploy target configurations.

See Also

Refer to the Examples page for more configuration examples of public Javascript projects.