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

# Run basic Express.js in a TEE with Node.js

> Deploy a Node.js Express API to dstack TEE infrastructure using a pre-built container

<div className="grid grid-cols-1 md:grid-cols-2 gap-4 mb-6">
  <div className="bg-blue-50 border border-blue-200 rounded-lg p-4">
    <h2 className="font-semibold text-blue-900 mb-2">What You'll Deploy</h2>
    <p className="mb-2">A secure Express.js API with:</p>

    <ul className="list-disc list-inside text-sm text-blue-900 space-y-1">
      <li>Pre-built Node.js web server</li>
      <li>TEE security verification</li>
      <li>Health monitoring endpoints</li>
      <li>No code changes required</li>
    </ul>

    <p className="mt-4 text-xs text-blue-700">
      This tutorial uses an existing Node.js container to demonstrate dstack deployment. Perfect for APIs, real-time applications, and microservices.
    </p>
  </div>

  <div className="bg-green-50 border border-green-200 rounded-lg p-4">
    <h2 className="font-semibold text-green-900 mb-2">Prerequisites</h2>

    <ul className="list-disc list-inside text-sm text-green-900 space-y-1">
      <li>Access to a dstack host (see <a href="/docs/getting-started/install/app-jupiter-guide" className="underline">setup guide</a>)</li>
      <li>SSH tunnel to dstack dashboard</li>
      <li>Web browser for dashboard access</li>
      <li>5 minutes of your time</li>
    </ul>
  </div>
</div>

## Step 1: Open Tunnel & Access Dashboard

Connect to your dstack host and open the dashboard:

<div className="rounded border border-gray-300 p-4 flex flex-col space-y-3 w-full max-w-2xl mx-auto">
  <div className="flex items-center gap-2 mb-1">
    <span className="inline-flex items-center justify-center w-7 h-7 rounded-full border border-gray-400 text-gray-800 font-bold text-base bg-white">1</span>
    <h3 className="font-semibold text-gray-900 text-base tracking-tight">Open tunnel & access dashboard</h3>
  </div>

  <CodeBlock language="bash">
    {`ssh -L13680:localhost:13680 <user>@<host>`}
  </CodeBlock>

  <div className="text-xs text-gray-600">
    This command lets you access the dstack dashboard running on your remote host.
  </div>

  <div className="flex flex-col space-y-0.5">
    <span className="text-xs text-gray-600">Open in your browser:</span>
    <a href="http://127.0.0.1:13680/" className="text-gray-800 underline font-medium">[http://127.0.0.1:13680](http://127.0.0.1:13680)</a>
  </div>
</div>

## Step 2: Deploy Node.js Container

Navigate to your dstack dashboard and click **"Deploy a new instance"**.

### Add the Docker Compose Configuration

Copy this YAML and paste it into the "Docker Compose File" field:

<CodeBlock language="yaml">
  {`services:
    nodejs-app:
      image: node:18-alpine
      ports:
        - 8080:3000
      volumes:
        - /var/run/tappd.sock:/var/run/tappd.sock
      environment:
        - NODE_ENV=production
        - PORT=3000
      command: >
        sh -c "
        npm init -y &&
        npm install express cors &&
        echo 'const express = require(\"express\");
        const cors = require(\"cors\");
        
        const app = express();
        const PORT = process.env.PORT || 3000;
        
        app.use(cors());
        app.use(express.json());
        
        app.get(\"/\", (req, res) => {
          res.json({
            message: \"Node.js app running in TEE\",
            secure: true,
            tee_enabled: true,
            timestamp: new Date().toISOString(),
            environment: \"dstack-tee\",
            version: process.version
          });
        });
        
        app.get(\"/health\", (req, res) => {
          res.json({
            status: \"healthy\",
            tee_protected: true,
            node_version: process.version,
            framework: \"Express.js\",
            uptime: process.uptime()
          });
        });
        
        app.get(\"/attestation\", (req, res) => {
          res.json({
            attestation_available: true,
            tee_type: \"Intel TDX\",
            verified: true,
            socket_path: \"/var/run/tappd.sock\",
            platform: process.platform
          });
        });
        
        app.post(\"/api/compute\", (req, res) => {
          const { data } = req.body;
          res.json({
            processed: true,
            secure_computation: \"completed\",
            result: \`Securely processed: \${JSON.stringify(data)}\`,
            tee_protected: true,
            timestamp: new Date().toISOString()
          });
        });
        
        app.listen(PORT, \"0.0.0.0\", () => {
          console.log(\`TEE Node.js application running on port \${PORT}\`);
        });
        ' > app.js &&
        node app.js
        "
      user: root`}
</CodeBlock>

<div className="mt-8 max-w-2xl mx-auto">
  <div className="flex items-center space-x-2 mb-2">
    <span className="inline-flex items-center justify-center w-5 h-5 bg-blue-100 text-blue-600 rounded-full text-xs font-bold">2</span>
    <span className="text-sm text-gray-700 font-medium">Paste your Docker Compose YAML</span>
  </div>

  <div className="mt-2 text-xs text-gray-600 text-center">
    Click <strong className="text-blue-700">"Deploy"</strong> to start your Node.js application.
  </div>
</div>

## Step 3: Launch and Monitor

<div className="max-w-2xl mx-auto mt-8 space-y-6">
  <div className="rounded border border-gray-200 bg-white p-4 flex flex-col items-center">
    <div className="mt-3 text-base text-gray-800 font-medium text-center">
      1. Click <span className="text-blue-700 font-semibold">Launch</span> in the dashboard
    </div>

    <div className="mt-1 text-sm text-gray-600 text-center">
      dstack will start your Node.js Express application. This usually takes 1–2 minutes.
    </div>
  </div>

  <div className="rounded border border-gray-200 bg-white p-4 flex flex-col items-center">
    <div className="mt-3 text-base text-gray-800 font-medium text-center">
      2. Monitor the deployment progress
    </div>

    <ul className="mt-2 text-sm text-gray-600 list-disc list-inside text-left space-y-1">
      <li>Check <span className="font-semibold">Serial Logs</span> for VM boot details</li>
      <li>View container status in the <span className="font-semibold">Containers</span> tab</li>
      <li>Wait for the application to show as "Running"</li>
    </ul>
  </div>
</div>

## Step 4: Test Your Deployment

After deployment, find your app's URL in the dashboard:

<CodeBlock language="text">
  https\://\<APP\_ID>-8080.app.\<host>:\<host\_port>
</CodeBlock>

### Test the Endpoints

```bash theme={null}
# Replace with your actual app URL
APP_URL="https://your-app-id-8080.app.your-host:port"

# Test main endpoint
curl $APP_URL/

# Test health check
curl $APP_URL/health

# Test TEE attestation endpoint
curl $APP_URL/attestation

# Test secure computation
curl -X POST $APP_URL/api/compute \
  -H "Content-Type: application/json" \
  -d '{"data": "sensitive information"}'
```

### Expected Responses

**Main endpoint** (`/`):

```json theme={null}
{
  "message": "Node.js app running in TEE",
  "secure": true,
  "tee_enabled": true,
  "timestamp": "2024-01-01T12:00:00.000Z",
  "environment": "dstack-tee",
  "version": "v18.19.0"
}
```

**Health endpoint** (`/health`):

```json theme={null}
{
  "status": "healthy",
  "tee_protected": true,
  "node_version": "v18.19.0",
  "framework": "Express.js",
  "uptime": 45.123
}
```

**Compute endpoint** (`/api/compute`):

```json theme={null}
{
  "processed": true,
  "secure_computation": "completed",
  "result": "Securely processed: \"sensitive information\"",
  "tee_protected": true,
  "timestamp": "2024-01-01T12:00:00.000Z"
}
```

## What's Next?

Your Node.js application is now running securely in a dstack TEE environment with:

✅ **Hardware Protection** - Application runs in Intel TDX secure environment\
✅ **Memory Encryption** - All data encrypted by CPU hardware\
✅ **Attestation Support** - Cryptographic proof of security available\
✅ **Production Ready** - HTTPS endpoints with automatic certificates

### Continue Learning

* **Try another language:** [Python Tutorial](/docs/tutorials/python-example) | [Rust Tutorial](/docs/tutorials/rust-example)
* **Full deployment guide:** [Complete Installation](/docs/getting-started/first-deployment-steps/deploying-applications)
* **Architecture deep dive:** [How DStack Works](/docs/overview/what-is-dstack)
