Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.
Draft
6 changes: 3 additions & 3 deletions docs/architecture/websites.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ classDef edgeLabel line-height:2;
flowchart TD
Developer["Developer"]
NitricUp["nitric up"]
Storage["Azure Storage"]
BlobStorage["Azure Blob Storage"]
FrontDoor["Azure Front Door"]
Rewrite["Azure API Management"]

Developer -->|Deploy| NitricUp
NitricUp -->|Upload Assets| Storage
NitricUp -->|Upload Assets| BlobStorage
NitricUp -->|Create CDN| FrontDoor
FrontDoor -->|Serve Static Files| Storage
FrontDoor -->|Serve Static Files| BlobStorage
FrontDoor -->|Rewrite /api/* to API| Rewrite

classDef default line-height:1;
Expand Down
4 changes: 2 additions & 2 deletions docs/batch.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ description: Running AI & Batch workloads with Nitric
Nitric provides functionality that allows you to run large-scale jobs in parallel across multiple virtual machines or compute resources. Unlike Nitric Services, which respond to real-time events (APIs, Schedules, etc.), Batch is intended to efficiently handle tasks that can be processed in batches, which means they don't need to run in real time but can be executed asynchronously. Batches can include tasks that require a lot of computing power, or access to GPU resources, such as machine learning model training, image processing, video transcoding, data processing, and data analysis.

<Note>
Batches are currently in [Preview](/reference/preview-features) and are
Batch services are currently in [Preview](/reference/preview-features) and are
currently only available in the following languages: JavaScript, Python, Go,
and Dart, using the nitric/[email protected], nitric/[email protected] or later.
</Note>

Nitric Batch is designed to be used in conjunction with Nitric Services, allowing you to run long-running, computationally intensive tasks in parallel with your real-time services. This allows you to build complex applications that can handle both real-time and batch processing workloads.

Batches are deployed to cloud services such as [AWS Batch](https://aws.amazon.com/batch/), [Azure Batch](https://azure.microsoft.com/en-au/products/batch), and [Google Cloud Batch](https://cloud.google.com/batch/docs). Nitric abstracts the underlying cloud provider, allowing you to run your batch jobs on any of the supported cloud providers without having to worry about the specifics of each provider.
Batches are deployed to cloud services such as [AWS Batch](https://aws.amazon.com/batch/) and [Google Cloud Batch](https://cloud.google.com/batch/docs). Nitric abstracts the underlying cloud provider, allowing you to run your batch jobs on any of the supported cloud providers without having to worry about the specifics of each provider.

## Enabling Batches

Expand Down
5 changes: 3 additions & 2 deletions docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const main = api('main')

main.get('/hello/:name', async ({ req, res }) => {
const { name } = req.params
ctx.res.body = `Hello ${name}`
res.body = `Hello ${name}`
})
```

Expand All @@ -38,7 +38,7 @@ const main = api('main')

main.get('/hello/:name', async ({ req, res }) => {
const { name } = req.params
ctx.res.body = `Hello ${name}`
res.body = `Hello ${name}`
})
```

Expand All @@ -61,6 +61,7 @@ Nitric.run()
// !collapse(1:5) collapsed
import (
"context"
"fmt"

"github.com/nitrictech/go-sdk/nitric"
"github.com/nitrictech/go-sdk/nitric/apis"
Expand Down
2 changes: 1 addition & 1 deletion docs/keyvalue.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Key value stores act as a database which provides the functionality for efficien

### Key

A key is a unique string that acts as a references to a value. Anytime a value is updated or read from a key value store, it is done so by referencing the key.
A key is a unique string that acts as a reference to a value. Anytime a value is updated or read from a key value store, it is done so by referencing the key.

### Value

Expand Down
2 changes: 1 addition & 1 deletion docs/providers/pulumi/azure.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ provider: nitric/azure@latest
<Note>
Nitric runs services (APIs, Schedules and Topic Subscribers) on Azure
Container Apps, which is unavailable in a [small number of
regions](https://azure.microsoft.com/en-au/explore/global-infrastructure/products-by-region/?products=container-apps&regions=all).
regions](https://azure.microsoft.com/en-us/explore/global-infrastructure/products-by-region/?products=container-apps&regions=all).
</Note>

The Azure provider is supported by the Nitric SDKs and CLI by default. However, credentials for an Azure account will be required when using the [up command](/reference/cli) from the CLI.
Expand Down
11 changes: 9 additions & 2 deletions docs/providers/pulumi/gcp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ Download & install the [latest CLI release](https://cloud.google.com/sdk/install
<TabItem label="Linux">

```bash
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-378.0.0-linux-x86_64.tar.gz
# Download the latest version
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-linux-x86_64.tar.gz

# Extract the archive
tar -xf google-cloud-cli-linux-x86_64.tar.gz

# Run the install script
./google-cloud-sdk/install.sh
```

</TabItem>
Expand Down Expand Up @@ -127,7 +134,7 @@ apis:
# Target an API by its nitric name
my-api:
# provide domains to be used for the api
description: An Azure API
description: A GCP API

# Add CDN configuration, required for websites deployments
# Available since v1.20.0
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/custom-containers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ RUN apt-get update -y && \
RUN pip install --upgrade pip pipenv

# Copy either requirements.txt or Pipfile
COPY requirements.tx[t] Pipfil[e] Pipfile.loc[k] ./
COPY requirements.txt Pipfile Pipfile.lock ./

# Guarantee lock file if we have a Pipfile and no Pipfile.lock
RUN (stat Pipfile && pipenv lock) || echo "No Pipfile found"
Expand Down
8 changes: 4 additions & 4 deletions docs/reference/env.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Nitric sets a number of environment variables to help you manage your project. T

If you are running your project in the cloud, build, or the run environment, Nitric provides prefixed Environment Variables, which you can find in the table below.

| Name | Description |
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| NITRIC_STACK_ID | The Stack ID of the project. Example: `coolkat-gcp-4c0wg0hg` |
| NITRIC_ENVIRONMENT | The Environment that the app is running on. The value can be either `cloud` (for deployed in the cloud), `run` (for stacks running in nitric run), or `build` (for stack code running during the deployment gathering phase). |
| Name | Description |
| ------------------ | ----------------------------------------------------------------------------------------------------------------- |
| NITRIC_STACK_ID | The unique identifier for your deployed stack (e.g., `coolkat-gcp-4c0wg0hg`) |
| NITRIC_ENVIRONMENT | The environment where the app is running: `cloud` (deployed), `run` (local stack), or `build` (during deployment) |

## Application Environment Variables

Expand Down
18 changes: 12 additions & 6 deletions docs/reference/nodejs/secrets/secret-put.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ import { secret } from '@nitric/sdk'

const keyRef = secret('apiKey').allow('put')

await keyRef.put('6c3199a3-094e-4797-bfc9-9ee2a7839286')
try {
await keyRef.put('6c3199a3-094e-4797-bfc9-9ee2a7839286')
console.log('Secret value stored successfully')
} catch (error) {
console.error('Error storing secret value:', error)
}
```

### Get the id of a new secret version
Expand All @@ -52,9 +57,10 @@ import { secret } from '@nitric/sdk'

const keyRef = secret('apiKey').allow('put')

const newApiKeyVersionRef = await keyRef.put(
'6c3199a3-094e-4797-bfc9-9ee2a7839286',
)

const versionId = newApiKeyVersionRef.version
try {
const newVersion = await keyRef.put('6c3199a3-094e-4797-bfc9-9ee2a7839286')
console.log('New secret version created:', newVersion.version)
} catch (error) {
console.error('Error creating new secret version:', error)
}
```
7 changes: 6 additions & 1 deletion docs/reference/nodejs/sql/sql-connection-string.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ import { sql } from '@nitric/sdk'
const db = sql('my-data')

// Should be called at runtime, such as in a service handler
const connStr = await db.connectionString()
try {
const connStr = await db.connectionString()
console.log('Database connection string:', connStr)
} catch (error) {
console.error('Error getting connection string:', error)
}
```

### Connect with Prisma
Expand Down
7 changes: 6 additions & 1 deletion docs/reference/nodejs/storage/bucket-file-read.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,10 @@ const assets = bucket('assets').allow('read')

const logo = assets.file('images/logo.png')

const logoData = await logo.read()
try {
const logoData = await logo.read()
console.log('Logo data:', logoData)
} catch (error) {
console.error('Error reading logo:', error)
}
```
19 changes: 16 additions & 3 deletions docs/reference/nodejs/storage/bucket-file-write.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ import { bucket } from '@nitric/sdk'
const assets = bucket('assets').allow('write')

const logo = assets.file('images/logo.png')

await logo.write(someImageData)
const imageData = new Uint8Array([
/* image data */
])

try {
await logo.write(imageData)
console.log('Logo written successfully')
} catch (error) {
console.error('Error writing logo:', error)
}
```

## Parameters
Expand All @@ -41,5 +49,10 @@ const assets = bucket('assets').allow('write')
const txt = assets.file('my-text-file.txt')
const buffer = Buffer.from('My Test File...')

await txt.write(buffer)
try {
await txt.write(buffer)
console.log('Text file written successfully')
} catch (error) {
console.error('Error writing text file:', error)
}
```
9 changes: 6 additions & 3 deletions docs/reference/nodejs/storage/bucket-on.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ assets.on('write', '/images/cat', (ctx) => {

// If `on` is called with a permissioned bucket, a file will also be provided with the request
accessibleAssets.on('write', '/images/dog', async (ctx) => {
const dogImage = await ctx.req.file.read()

console.log(dogImage)
try {
const dogImage = await ctx.req.file.read()
console.log(dogImage)
} catch (error) {
console.error('Error reading dog image:', error)
}
})
```

Expand Down
19 changes: 15 additions & 4 deletions docs/reference/nodejs/websocket/websocket-on.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,13 @@ const socket = websocket('socket')
const connections = kv('connections').allow('get', 'set', 'delete')

socket.on('connect', async (ctx) => {
const connectionList = await connections.get('connections')
await connections..set('connections', [
let connectionList = []
try {
connectionList = await connections.get('connections')
} catch (e) {
console.log('Creating new connections store')
}
await connections.set('connections', [
...connectionList,
{
// store any metadata related to the connection here
Expand All @@ -89,10 +94,16 @@ socket.on('connect', async (ctx) => {
})

socket.on('disconnect', async (ctx) => {
const connectionList = await connections.get('connections')
let connectionList = []
try {
connectionList = await connections.get('connections')
} catch (e) {
console.log('No connections found')
return
}
await connections.set(
'connections',
connectionList.filter((c) => c.connectionId === ctx.req.connectionId)
connectionList.filter((c) => c.connectionId === ctx.req.connectionId),
)
})
```
Expand Down
8 changes: 7 additions & 1 deletion docs/reference/nodejs/websocket/websocket-send.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ socket.on('disconnect', async (ctx) => {
})

const broadcast = async (data) => {
const conns = await connections.get('connections')
let conns = {}
try {
conns = await connections.get('connections')
} catch (e) {
console.log('No connections found')
return
}

await Promise.all(
Object.keys(conns).map(async (connectionId) => {
Expand Down
8 changes: 3 additions & 5 deletions docs/schedules.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ schedule('send-reminder').cron('0 22 * * 1-5', async (ctx) => {

```python !!
from nitric.resources import schedule
from nitric.resources import Nitric
from nitric.application import Nitric

# Run every 5 minutes
processor = schedule("process-transactions")
Expand Down Expand Up @@ -79,7 +79,7 @@ import (

func main() {
// Run every 5 minutes
nitric.NewSchedule("process-transactions").Every("5 minutues", func(ctx *schedules.Ctx) {
nitric.NewSchedule("process-transactions").Every("5 minutes", func(ctx *schedules.Ctx) {
fmt.Printf("processing at %s\n", time.Now().Format(time.RFC3339))
})
// Run at 22:00 Monday through Friday.
Expand All @@ -97,15 +97,13 @@ import 'package:nitric_sdk/nitric.dart';
// run every 5 minutes
Nitric.schedule("process-transactions").every("5 minutes", (ctx) async {
// add code to run here
print("processing transaction")
return ctx;
print("processing transaction");
});

// Run at 22:00 Monday through Friday
Nitric.schedule("send-reminder").cron("0 22 * * 1-5", (ctx) async {
// add code to run here
print("sending reminder");
return ctx;
});
```

Expand Down
2 changes: 1 addition & 1 deletion docs/secrets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ api_key = secret("api-key").allow("put")
latest = await api_key.put("a new secret value")

# We can get the version ID of our newly stored value
latest.version
print(latest.version)

Nitric.run()
```
Expand Down
7 changes: 3 additions & 4 deletions docs/sql.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ Nitric provides functionality for provisioning and interacting with SQL database
If you're interested in the architecture, provisioning, or deployment steps, they can be found [here](/architecture/sql).

<Note>
SQL databases are currently in preview and only support PostgreSql deployed to
AWS using the <br className="hidden lg:block" />
`nitric/aws` and `nitric/awstf` providers, GCP with the `nitric/azure`
provider, or Azure with the `nitric/azure` provider.
SQL databases are currently in preview and only support PostgreSQL deployed to
AWS using the `nitric/aws` and `nitric/awstf` providers, GCP using the
`nitric/gcp` provider, or Azure using the `nitric/azure` provider.
</Note>

<Note>
Expand Down
Loading