Getting started

After installing the Nitric CLI, you can start building a project.

Using the new command

The Nitric CLI's new command provides prompts to scaffold new projects from templates. Here's an example of creating a new project from a template:

nitric new
? What is the name of the project? hello-world
? Choose a template: official/TypeScript - Starter

Navigate to the new project directory and install the dependencies:

cd hello-world

npm install

Your project should now look like this:

|  +-- hello.ts
|  ...

Running your app

Nitric provides a local development server offering emulated versions of cloud services, suitable for local development/testing. You can use the Nitric CLI to start the local server using the nitric start command.

Once the server has started, you can run your project like any other application. The starter templates, provide a recommended setup for each language.

npm run dev

After your function is running, it will register itself with the server. All the APIs are locally hosted on their own port, which will be displayed in the CLI output as http://localhost:<port_number>.

The output will also show the local dashboard URL, the dashboard will automatically refresh with API details and other useful tools for building your application.

In this case, the output should be:

Api  | Endpoint
main | http://localhost:4001

Dev Dashboard | http://localhost:49152

Once the API is registered, you can test the API using any HTTP client, your browser, or the local dashboard:

curl http://localhost:4001/hello/John
Hello John

Your local dashboard

Access the local development dashboard by opening the URL and port displayed in the CLI output.

The development dashboard is a powerful tool designed to help you move faster when developing new features. With the API explorer, you can easily access automatically generated endpoints and path params. Additionally, the Schedules Explorer allows you to trigger your schedules with ease, making it easier than ever to stay on top of your tasks. Make the most of your local development process with this essential tool.

Watch this brief video to see the development dashboard in action. You'll get a firsthand look at how the dashboard streamlines your development process by showcasing the debugging of APIs and schedules in the popular code editor, VS Code.

Making updates

Most of Nitric's language templates enable hot-reloading by default, so at this point, you can start making changes to functions and see what happens.

Start by opening the hello function in your editor and adding a new route to the API, then save, and execute the file:

import { api } from '@nitric/sdk'

const helloApi = api('main')

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

// Let's add a 'goodbye' route to the API, like this:
helloApi.get('/goodbye/:name', async (ctx) => {
  const { name } = ctx.req.params
  ctx.res.body = `Goodbye ${name}`
  return ctx

After saving the file, the new route will be registered and you can test it:

curl http://localhost:4001/goodbye/John
Goodbye John

When you're finished testing, you can stop your application and the Nitric Server.

Deploying the app

Now that you've implemented a basic API and tested that it works, you can deploy it to one or more cloud platforms. Applications built with Nitric can be automatically deployed and run on multiple cloud providers without any code changes.

The first step is to set up your credentials for the cloud provider.

You'll then need to create a stack that represents your project and a deployment target.

nitric stack new

Follow the prompts to create a stack for your provider, this example will use aws.

? What do you want to call your new stack? dev
? Which Cloud do you wish to deploy to? aws
? select the region us-east-1

Now you can deploy your dev stack with the up command.

nitric up
 SUCCESS  Configuration gathered (2s)
 SUCCESS  Images built (3s)
 Deployed  Function/hello (15)
 Deployed  Stack (25s)
| API  | Endpoint                                               |
| main |   |

When the deployment is complete, go to the relevant cloud console and you'll be able to see and interact with your API.

To tear down the stack use the down command:

nitric down

What's next?