> ## 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.

# NodeJS Application Overview

> This guide covers Node.js setup, testing, and running a simple application, along with integrating it into a GitHub Actions workflow.

In this guide, you’ll learn what Node.js is and how to set up, test, and run a simple “Hello World” application. We’ll also show you how to integrate this Node.js project into a custom [GitHub Actions](https://docs.github.com/en/actions) workflow for continuous integration.

## What Is Node.js?

Node.js is an open-source, cross-platform JavaScript runtime built on Chrome’s [V8 engine](https://v8.dev). It enables you to run JavaScript on the server side, unifying your front-end and back-end development in a single language. Installing Node.js also provides npm (Node Package Manager) for managing your dependencies.

<Callout icon="lightbulb" color="#1CB2FE">
  * High performance with non-blocking I/O
  * Vast ecosystem via `npm`
  * Single language for client and server
</Callout>

## Prerequisites

Before you begin, ensure you have Node.js and npm installed on your machine.

```bash theme={null}
node -v    # e.g., v18.16.0
npm -v     # e.g., 9.8.1
```

<Callout icon="triangle-alert" color="#FF6B6B">
  Always verify that your CI/CD environment (like GitHub Actions) uses the same Node.js version as your local setup to avoid inconsistencies.
</Callout>

## Sample Project Structure

Below is a minimal Node.js project that returns “Hello World” from a `/hello` endpoint.

| File         | Purpose                                                        |
| ------------ | -------------------------------------------------------------- |
| package.json | Metadata (name, version), dependencies, and script definitions |
| index.js     | Main application file (defines server and routes)              |
| test.js      | Simple test suite to verify the logic in `index.js`            |

## Installing Dependencies

Install all required packages listed in `package.json`:

```bash theme={null}
npm install
```

On success, npm generates a `node_modules` directory containing your project’s dependencies.

## Running Your Tests

Run the test suite defined in `test.js`:

```bash theme={null}
npm test
```

Expected output:

```bash theme={null}
> my-app@1.0.0 test
> node test.js

Testing is successful
```

## Starting the Application

Launch the server:

```bash theme={null}
npm start
```

You’ll see:

```bash theme={null}
> my-app@1.0.0 start
> node index.js

App listening on port 3000
```

In another terminal or your browser, request the `/hello` endpoint:

```bash theme={null}
curl http://localhost:3000/hello
# Hello World!
```

## GitHub Actions Workflow

Automate your CI/CD pipeline by adding a workflow file at `.github/workflows/ci.yml`:

```yaml theme={null}
name: Node.js CI

on: [push, pull_request]

jobs:
  build-and-test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18.x]

    steps:
      - uses: actions/checkout@v3

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}

      - name: Install dependencies
        run: npm install

      - name: Run tests
        run: npm test

      - name: Start application
        run: npm start
```

## Links and References

* [Node.js Official Website](https://nodejs.org/)
* [npm Documentation](https://docs.npmjs.com/)
* [GitHub Actions](https://docs.github.com/en/actions)
* [V8 JavaScript Engine](https://v8.dev/)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/github-actions/module/6136c7b5-8fe0-4a84-ae77-0274623512d5/lesson/26afff18-d33c-4607-8e8e-130ceb4f4d1a" />
</CardGroup>
