> For the complete documentation index, see [llms.txt](https://docs.release.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.release.com/guides-and-examples/common-setup-examples/define-a-static-javascript-service.md).

# Static JavaScript service

How to define a new static JavaScript service or convert an existing Docker service to use a static JavaScript build deployed to a CDN

## Define a static JavaScript service

Creating a static JavaScript service in Release requires the following parameters:

* `static`: `true` for a static build, `false` to switch back to a Docker build.
* `build_base`: the path to the JavaScript project in your repository.
* `build_command`: your JavaScript build command.
* `build_output_directory`: the directory the build command outputs the build to.

Here's an example static build:

```yaml
services:
- name: frontend
  static: true
  build_command: GENERATE_SOURCEMAP=false yarn build
  build_base: frontend
  build_output_directory: build/
```

### Converting an existing Docker service to static JavaScript

Release allows you to define a service with both static JavaScript and Docker service parameters. You can also easily convert any single page JavaScript Docker service to a static JavaScript build.

Here is a Docker-based JavaScript frontend that was generated from a `docker-compose` by Release:

```yaml
services:
- name: frontend
  image: acme-co/awesome-project/frontend
  ports:
  - type: node_port
    target_port: '3000'
    port: '3000'
  has_repo: true
  memory:
    limits: 4Gi
    requests: 100Mi
```

You can update this to use static builds by adding the same parameters for defining a static JavaScript service as outlined above. Use the `static` parameter to switch the service between a static JavaScript build and running in a Docker container.

```yaml
services:
- name: frontend
  image: acme-co/awesome-project/frontend
  ports:
  - type: node_port
    target_port: '3000'
    port: '3000'
  has_repo: true
  memory:
    limits: 4Gi
    requests: 100Mi
  static: true
  build_command: yarn build
  build_base: frontend
  build_output_directory: build/
```

### Setting the NodeJS Javascript version

During builds, you can control the version of NodeJS that is used by supplying the version information in a `.nvmrc` file. We recommend setting the file at the root of your project, but you can also create the file at the subtree where your project lives. You can read the [documentation](https://github.com/nvm-sh/nvm#nvmrc) to find more details. This is a simple example that will use the version that you specify from your local version:

```shell
cd /project/root
node -v > .nvmrc
git add .nvmrc
git commit -m "Set javascript version"
git push
```

## Deprecated

This section is deprecated and may be removed at a later date.

### Adding basic authentication to static sites

If you want the benefits of a static CDN site but don’t want your site to be public, Release has a simple way to add [basic authentication](https://en.wikipedia.org/wiki/Basic_access_authentication) to your static content via our proprietary Edge Routing System.

{% hint style="warning" %}
Static site basic authentication does not allow for multiple users with their own passwords. It is only suitable for a single shared user and password scheme. It is not suitable for production environments.
{% endhint %}

{% hint style="danger" %}
Basic authentication does not use encryption to secure usernames and/or passwords. It is not suitable for applications running in production.
{% endhint %}

If you would like to add basic authentication to your site, set up a static application as shown in the previous section. Then, find the `hostnames` entry for your static application as shown in this example:

```yaml
hostnames:
  - api-${env_id}-${domain}
  - web-client-${env_id}-${domain}
```

Replace the `web-client-...` line with the following example:

```yaml
hostnames:
  - api-${env_id}-${domain}
routes:
- name: web-client
  hostname: web-client-${env_id}-${domain}
  auth:
    username: admin
    password: letmein
  rules:
  - service: web-client
    path: "/"
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.release.com/guides-and-examples/common-setup-examples/define-a-static-javascript-service.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
