> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo InstallSetup NodeJS Build Tool

> This tutorial explains how to integrate Node.js into Jenkins pipelines using host installation and Jenkins-managed tools.

In this tutorial, you will learn how to integrate Node.js into your Jenkins pipelines by using both the host installation and Jenkins-managed Node.js tool. By the end, you'll be able to run Node.js commands in freestyle jobs across controllers and agents.

<Callout icon="lightbulb" color="#1CB2FE">
  * A running Jenkins controller (version 2.x or later).
  * Shell access to the Jenkins host machine.
  * Administrative privileges to install plugins.
</Callout>

## 1. Verify Node.js on the Jenkins Host

SSH into the Jenkins server and confirm that Node.js and npm are installed:

```bash theme={null}
node -v
npm -v
systemctl status jenkins
# ● jenkins.service - Jenkins Continuous Integration Server
#    Active: active (running)
```

If Node.js is available on the controller, freestyle jobs can execute `node` and `npm` directly. Agents without Node.js will fail unless you provide a managed installation.

## 2. Test Node.js in a Freestyle Project

1. In Jenkins, click **New Item**, enter `npm-version-test`, choose **Freestyle project**, then **OK**.
2. Under **Build** → **Execute shell**, add:

   ```bash theme={null}
   node -v
   npm -v
   ```

<Frame>
  ![The image shows a Jenkins interface where a user is creating a new item, with options to select different project types like Freestyle project, Pipeline, and others. The item name entered is "npm-version-test."](https://kodekloud.com/kk-media/image/upload/v1752871059/notes-assets/images/Certified-Jenkins-Engineer-Demo-InstallSetup-NodeJS-Build-Tool/jenkins-new-item-npm-version-test.jpg)
</Frame>

3. Save and run the job. You should see:

   ```bash theme={null}
   Started by user example
   Building in workspace /var/lib/jenkins/workspace/npm-version-test
   [npm-version-test] $ /bin/sh -xe /tmp/jenkins.sh
   + node -v
   v20.16.0
   + npm -v
   10.8.1
   Finished: SUCCESS
   ```

<Frame>
  ![The image shows a Jenkins dashboard for a project named "npm-version-test," displaying build status and history with options for configuration and project management.](https://kodekloud.com/kk-media/image/upload/v1752871060/notes-assets/images/Certified-Jenkins-Engineer-Demo-InstallSetup-NodeJS-Build-Tool/jenkins-dashboard-npm-version-test.jpg)
</Frame>

<Callout icon="triangle-alert" color="#FF6B6B">
  If your builds run on agents without Node.js, this job will fail. To ensure consistency, use Jenkins-managed tools.
</Callout>

## 3. Install the NodeJS Plugin

Add Node.js as a managed tool in Jenkins:

1. Go to **Manage Jenkins** → **Manage Plugins** → **Available**.
2. Search for **NodeJS**, select **NodeJS plugin (v1.6.2)**, then **Install without restart**.

<Frame>
  ![The image shows a Jenkins interface with a search for "NodeJS" in the available plugins section, displaying the NodeJS plugin version 1.6.2.](https://kodekloud.com/kk-media/image/upload/v1752871062/notes-assets/images/Certified-Jenkins-Engineer-Demo-InstallSetup-NodeJS-Build-Tool/jenkins-nodejs-plugin-search-1-6-2.jpg)
</Frame>

Wait for the installation to complete:

<Frame>
  ![The image shows a Jenkins dashboard displaying the download progress of plugins, with all tasks marked as successful. The interface includes options for managing plugins and settings.](https://kodekloud.com/kk-media/image/upload/v1752871063/notes-assets/images/Certified-Jenkins-Engineer-Demo-InstallSetup-NodeJS-Build-Tool/jenkins-dashboard-plugin-download-progress.jpg)
</Frame>

## 4. Configure Node.js as a Global Tool

1. Navigate to **Manage Jenkins** → **Global Tool Configuration**.

2. Under **NodeJS installations**, click **Add NodeJS**, then fill in:

   * **Name**: `Node.js 22.6.0`
   * **Install automatically**: checked
   * **Version**: `22.6.0`

3. Click **Save**.

<Frame>
  ![The image shows a Jenkins configuration screen for adding NodeJS, with options to install a specific version and configure global npm packages.](https://kodekloud.com/kk-media/image/upload/v1752871064/notes-assets/images/Certified-Jenkins-Engineer-Demo-InstallSetup-NodeJS-Build-Tool/jenkins-nodejs-configuration-screen.jpg)
</Frame>

## 5. Use the Managed Node.js in a Freestyle Job

1. Open the **npm-version-test** job and click **Configure**.
2. In **Build Environment**, enable **Provide Node & npm bin/ folder to PATH**, then select **Node.js 22.6.0**.

<Frame>
  ![The image shows a configuration screen for a build environment, likely in a CI/CD tool, with options for Node.js installation and npm settings. The interface includes checkboxes and dropdown menus for various settings, such as providing Node & npm bin folder to PATH and executing shell commands.](https://kodekloud.com/kk-media/image/upload/v1752871065/notes-assets/images/Certified-Jenkins-Engineer-Demo-InstallSetup-NodeJS-Build-Tool/ci-cd-build-environment-node-npm.jpg)
</Frame>

3. Save and trigger the build. The first run installs Node.js on the controller:

   ```bash theme={null}
   Started by user example
   Building in workspace /var/lib/jenkins/workspace/npm-version-test
   Unpacking https://nodejs.org/dist/v22.6.0/node-v22.6.0-linux-x64.tar.gz to /var/lib/jenkins/tools/.../nodejs-22-6-0
   [npm-version-test] $ /bin/sh -xe /tmp/jenkins.sh
   + node -v
   v22.6.0
   + npm -v
   10.8.2
   Finished: SUCCESS
   ```

Subsequent builds reuse the cached installation, ensuring consistent Node.js versions across all agents.

## Summary

| Step                      | Description                                                 |
| ------------------------- | ----------------------------------------------------------- |
| Verify Host Installation  | Check `node -v` and `npm -v` on the Jenkins controller.     |
| Freestyle Project Test    | Run a basic freestyle job using host-installed Node.js.     |
| Install NodeJS Plugin     | Add NodeJS plugin via **Manage Plugins**.                   |
| Global Tool Configuration | Define Node.js under **Global Tool Configuration**.         |
| Use Managed Node.js       | Enable Node.js in **Build Environment** of a freestyle job. |

## Links and References

* [Jenkins Documentation](https://www.jenkins.io/doc/)
* [NodeJS Plugin](https://plugins.jenkins.io/nodejs/)
* [Node.js Official Site](https://nodejs.org/)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/certified-jenkins-engineer/module/73d0066f-a01f-4d13-a00c-c9baf9aae603/lesson/adb86404-e404-46e0-9a10-42601b3a5a33" />
</CardGroup>
