NodeJS
Use a CI pipeline to build and test a NodeJS application.
You can build and test a Node.js application using a Linux platform on Harness Cloud or a self-managed Kubernetes cluster build infrastructure.
This guide assumes you've created a Harness CI pipeline.
Install dependencies
Use Run step to install dependencies in the build environment.
- step:
type: Run
identifier: dependencies
name: Dependencies
spec:
shell: Sh
command: |-
npm install express@4.18.2 --no-save- step:
type: Run
identifier: dependencies
name: Dependencies
spec:
connectorRef: YOUR_IMAGE_REGISTRY_CONNECTOR
image: node:14.18.2-alpine
command: |-
npm install express@14.18.2 --no-saveCache dependencies
Cache Node dependencies with Cache Intelligence.
Add caching.enabled.true to your stage.spec:
- stage:
spec:
caching:
enabled: trueYou can use built-in steps to:
Build and run tests
Add Run steps to build and run tests in Harness CI.
Visualize test results
If you want to view test results in Harness, make sure your test commands produce reports in JUnit XML format and that your steps include the reports specification.
Test splitting
You can use test splitting (parallelism) to improve test times.
Specify version
Node is pre-installed on Hosted Cloud runners. For details about all available tools and versions, go to Platforms and image specifications.
If your application requires a specific Node version, add a Run step to install it.
Specify the desired Node Docker image tag in your steps. There is no need for a separate install step when using Docker.
Full pipeline examples
Here's a YAML example of a pipeline that:
Tests a Node code repo.
Builds and pushes an image to Docker Hub.
This pipeline uses Harness Cloud build infrastructure and Cache Intelligence.
If you copy this example, replace the placeholder values with appropriate values for your Harness project, connector IDs, account/user names, and repo names.
Next steps
Now that you have created a pipeline that builds and tests a Node app, you could:
Create triggers to automatically run your pipeline.
Add steps to build and upload artifacts.
Add a step to build and push an image to a Docker registry.
Last updated
Was this helpful?