# Volumes

Persistent storage volumes for services. Volumes provide a directory that persists across deployments, useful for file uploads, caches, and other data that needs to survive restarts.

Volumes are defined as sub-blocks within a service. Each volume has a name and exposes a `path` attribute that resolves to the directory path.

```hcl
service "api" {
  build = build.api
  command = "node server.js"

  volume "uploads" {}

  env = {
    UPLOADS_DIR = volume.uploads.path
  }
}
```

## Available volume attributes

- `path` - Absolute path to the volume directory

## How it works

- **In production (Kubernetes):** Each volume creates a PersistentVolumeClaim. The `path` attribute resolves to `/volumes/{name}` inside the container.
- **In development (`specific dev`):** Each volume maps to a local directory at `.specific/keys/.../data/volumes/{service}/{name}/`. The `path` attribute resolves to this local directory.

Volume data persists across deployments and dev server restarts.

## Multiple volumes

A service can define multiple volumes:

```hcl
service "api" {
  build = build.api
  command = "node server.js"

  volume "uploads" {}
  volume "cache" {}

  env = {
    UPLOADS_DIR = volume.uploads.path
    CACHE_DIR   = volume.cache.path
  }
}
```

## Example usage (Node.js)

```javascript
import fs from "fs";
import path from "path";

const uploadsDir = process.env.UPLOADS_DIR;

// Write a file
fs.writeFileSync(path.join(uploadsDir, "myfile.txt"), "Hello, world!");

// Read it back (persists across restarts)
const content = fs.readFileSync(path.join(uploadsDir, "myfile.txt"), "utf8");
```
