Search Results for ""

Node.js - JavaScript Tutorial

This document provides a walkthrough of the .circleci/config.yml file for a Node.js sample application.

Quickstart: Demo JavaScript Node.js Reference Project

We maintain a reference JavaScript project to show how to build a React.js app on CircleCI with version: 2.1 configuration:

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

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 the CircleCI application and click the Set Up 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.

Sample Configuration

Below is the .circleci/config.yml file in the demo project.

orbs: # declare what orbs we are going to use
  node: circleci/node@2.0.2 # the node orb provides common node-related configuration 

version: 2.1 # using 2.1 provides access to orbs and other features

workflows:
  matrix-tests:
    jobs:
      - node/test:
          version: 13.11.0
      - node/test:
          version: 12.16.0
      - node/test:
          version: 10.19.0

Config Walkthrough

Using the 2.1 Node orb sets an executor from CircleCI’s highly cached convenience images built for CI and allows you to set the version of NodeJS to use. Any available tag in the docker image list can be used.

The Node Orb test command will test your code with a one-line command, with optional parameters.

Matrix jobs are a simple way to test your Node app on various node environments. For a more in depth example of how the Node orb utilizes matrix jobs, see our blog on matrix jobs. See documentation on pipeline parameters to learn how to set a node version via Pipeline parameters.

Success! You just set up a Node.js app to build on CircleCI with version: 2.1 configuration. Check out our project’s pipeline page to see how this looks when building on CircleCI.

See Also

  • See the Deploy document for example deploy target configurations.
  • Refer to the Examples page for more configuration examples of public JavaScript projects.
  • 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.