Nitric Documentation

Build cloud backends that run anywhere, fast.


Nitric is a declarative cloud framework with common resources like APIs, websockets, databases, queues, topics, buckets, and more.

However, Nitric doesn't just deploy the resources, it helps you interact with them. It also makes them pluggable, so you can swap services or even whole clouds without changing your code.

It's what's missing between applications and infrastructure automation.

Oh, and it supports basically any language, like JavaScript, TypeScript, Python, Go, you name it.

Node.js LogoPython LogoGo LogoDart LogoC# .NET LogoJVM Logo

If you're familiar Nitric already, you might want to jump to the Installation, Guides or Resources sections. Otherwise, keep reading to learn more about Nitric.


Services

Services are the heart of Nitric apps, they're the entrypoints to your code. They can serve as APIs, websockets, schedule handlers, subscribers and a lot more. You create services by telling Nitric where to look for your code and how to run it.

nitric.yaml
name: example
services:
  - match: services/*.ts
    start: npm run dev:services $SERVICE_PATH

You might have one service that handles everything, or a service for each route. It's up to you. Every matched service becomes a container, allowing them run and scale independently.


Resources

Resources are the building blocks of your apps. They're the databases, queues, buckets, etc. that your services interact with. To request a resource, import the resource type and create one with a name.

services/example.js
import { bucket } from '@nitric/sdk'

const profiles = bucket('profiles').allow('read', 'write', 'delete')

Nitric collects everything your services request. When you deploy, the deployment plugin you choose creates the resources and services, then links them all together.


Deployment Plugins (Providers)

Nitric is designed to be independent of any platform, so you can run your apps anywhere. You can deploy to AWS, Azure, GCP, your own Kubernetes cluster or a single server. You could even deploy to multiple clouds at once.

Are the differences between a bucket on AWS and a bucket on Azure important to most apps? We don't think so. So why should the code be different?

Nitric abstracts away API layer differences, so you can focus on your app. The part that makes that possible is a plugin, we call a Provider.

nitric.prod.yaml
provider: nitric/aws@1.1.1
region: us-east-1

We have several providers built-in with IaC from Pulumi or Terraform, but you can build your own with any tools you prefer and deploy anywhere.


Projects

Projects built with Nitric don't have many restrictions. You can use most languages, libraries, tools, clouds, services, mostly anything you like. But, you need to have a nitric.yaml file in the root of your project.

nitric.yaml
name: example
services:
  - match: services/*.ts
    start: npm run dev:services $SERVICE_PATH

Nitric uses this to find your services, then it turns each service into a container, runs them in deployment mode to match the resources you requested and gives the result to the Provider - which either generates IaC (like Terraform) or automatically deploys your app.

So, a project structure might look something like this:

example/
โ”œโ”€โ”€ nitric.yaml
โ”œโ”€โ”€ services/
โ”‚   โ””โ”€โ”€ orders.js
โ”‚   โ””โ”€โ”€ users.js
โ””โ”€โ”€ package.json

CLI

Nitric has a CLI to help you create, manage, run and deploy your projects. We recommend installing it with a package manager:

brew install nitrictech/tap/nitric

New

You can create a new project from a template with the new command.

nitric new

Start

You can run your project locally with the start command.

nitric start

Deploy

You can deploy your project with the up command, once you have a stack file (deployment target).

# Create a new stack (deployment target)
nitric stack new
# Deploy to the stack, using the provider in the stack file
nitric up

Tear Down

You can tear down your project with the down command.

nitric down

Local development

Sometimes you'll want to run your app locally. We don't mean "binds to a cloud environment and syncs your code, but doesn't work without Wifi" local, we mean "runs on your machine, on a desert island" local.

nitric start hosts entrypoints like APIs, websockets, and schedules, as well as resources like databases, topics, queues, key/value stores and buckets.

It also provides a Dashboard to interact with your resources, so you can trigger schedules without waiting, or topics without a publisher, or upload test files to a bucket. It even produces a live architecture diagram of your services and resources as your code updates.

screen shot of the local development dashboard

Extension & Escape Hatches

The services of cloud providers are vast, we can't cover everything and we shouldn't. Many services are unique enough that abstraction would be a disservice. Nitric aims to make common "table stakes" services easy to use, but we never want to limit you.

Here are some ways you can extend or escape Nitric.

Runtime

If you need to access a service in a way Nitric doesn't support, you can always use the provider's SDK directly. Code like this will always work:

// Import the AWS SDK
import { S3Client } from '@aws-sdk/client-s3'

// Use it like you normally would
const s3 = new S3Client({ region: 'us-east-1' })
const { Contents } = await s3.listObjectsV2({ Bucket: 'my-bucket' })

Overriding

If you need to change how Nitric deploys a resources or how it interacts with a service at runtime, you can extend or modify a provider.

Full Customization

If you need to deploy to a new platform or new set of services that Nitric doesn't support, you can build your own provider. This is a bit more advanced, but it's the ultimate escape hatch.

The included providers are written in Go and built using Terraform or Pulumi, but you can use any language or tool you like.

Additional Resources

If you need to use a service/resource that Nitric doesn't support, you do that like you always would. Nitric doesn't get in the way of you using the cloud, it just makes it easier.


What now?

If you're still not sure what to make of Nitric, maybe start with the Concepts section, otherwise the best way to learn is to dive into the Guides and start building your first project.