Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 265ca73

Browse files
wip ensure up to date guides and docs
1 parent 36763c2 commit 265ca73

File tree

8 files changed

+192
-209
lines changed

8 files changed

+192
-209
lines changed

docs/get-started/quickstart.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Your project should now look like this:
159159

160160
```txt TypeScript
161161
+--services/
162-
| +-- hello.ts
162+
| +-- api.ts
163163
+--node_modules/
164164
| ...
165165
+--package-lock.json
@@ -174,7 +174,7 @@ Your project should now look like this:
174174

175175
```txt JavaScript
176176
+--services/
177-
| +-- hello.js
177+
| +-- api.js
178178
+--node_modules/
179179
| ...
180180
+--package-lock.json
@@ -220,7 +220,7 @@ Your project should now look like this:
220220

221221
```txt Dart
222222
+--services/
223-
| +-- hello.dart
223+
| +-- api.dart
224224
+--analysis_options.yaml
225225
+--pubspec.lock
226226
+--pubspec.yaml
@@ -270,7 +270,7 @@ Start by opening the `hello` service in your editor and adding a new route to th
270270

271271
<CodeSwitcher tabs>
272272

273-
```typescript !! title:services/hello.ts
273+
```typescript title:services/api.ts
274274
import { api } from '@nitric/sdk'
275275

276276
const helloApi = api('main')
@@ -289,7 +289,7 @@ helloApi.get('/goodbye/:name', async (ctx) => {
289289
})
290290
```
291291

292-
```javascript !! title:services/hello.js
292+
```javascript title:services/api.js
293293
import { api } from '@nitric/sdk'
294294

295295
const helloApi = api('main')
@@ -308,7 +308,7 @@ helloApi.get('/goodbye/:name', async (ctx) => {
308308
})
309309
```
310310

311-
```python !! title:services/hello.py
311+
```python title:services/api.py
312312
from nitric.resources import api
313313
from nitric.application import Nitric
314314

@@ -357,7 +357,7 @@ func main() {
357357
}
358358
```
359359

360-
```dart !! title:services/hello.dart
360+
```dart title:services/api.dart
361361
import 'package:nitric_sdk/nitric.dart';
362362
363363
void main() {

docs/guides/nodejs/expressjs.mdx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ languages:
77
- typescript
88
- javascript
99
published_at: 2023-07-10
10-
updated_at: 2024-03-18
10+
updated_at: 2024-12-27
1111
---
1212

1313
# Enhance Express.js Apps with Cloud Resources
@@ -42,7 +42,7 @@ You can go ahead and open this new project in your editor of choice. You should
4242

4343
```txt
4444
├── services
45-
│ ├── hello.js
45+
│ ├── api.js
4646
├── node_modules
4747
│ ├── ...
4848
├── .gitignore
@@ -55,17 +55,9 @@ You can go ahead and open this new project in your editor of choice. You should
5555

5656
In this structure you'll notice the `services` folder. By default, this is where Nitric expects the entrypoint code for your application. However, that's just a convention, we can change that to anything else that suits our needs.
5757

58-
Let's start by replacing the default `hello.js` service with an `app.js` file ready for the Express.js application:
59-
60-
```bash
61-
rm ./services/hello.js
62-
63-
touch ./services/app.js
64-
```
65-
6658
Now, let's add some express code to get things started.
6759

68-
```javascript {{ label: 'services/app.js' }}
60+
```javascript title:services/api.js
6961
import express from 'express'
7062
import { http } from '@nitric/sdk'
7163
const app = express()
@@ -100,9 +92,9 @@ Hello World!
10092

10193
With everything working so far, now is a good time to see how we can add new resources to the Express app using Nitric. In this example, let's add a pub/sub topic which allows us to perform work in the background, but still respond quickly via the HTTP API.
10294

103-
You can update the `app.js` file like so:
95+
You can update the `api.js` file like so:
10496

105-
```javascript {{ label: 'services/app.js' }}
97+
```javascript title:services/api.js
10698
import express from 'express'
10799
import { http, topic } from '@nitric/sdk'
108100

@@ -125,7 +117,7 @@ touch services/worker.js
125117

126118
Add this code to that file:
127119

128-
```javascript {{ label: 'services/worker.js' }}
120+
```javascript title:services/worker.js
129121
import { topic } from '@nitric/sdk'
130122

131123
const sleep = (ms) => new Promise((res) => setTimeout(res, ms))
@@ -166,7 +158,7 @@ nitric stack new
166158

167159
This command will create a file named `nitric.dev.yaml`, with contents like this:
168160

169-
```yaml {{ label: 'nitric.dev.yaml' }}
161+
```yaml title:nitric.dev.yaml
170162
provider: nitric/[email protected]
171163
region: us-east-1
172164
```

docs/guides/nodejs/fastify.mdx

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ languages:
77
- typescript
88
- javascript
99
published_at: 2023-07-12
10-
updated_at: 2024-03-18
10+
updated_at: 2024-12-27
1111
---
1212

1313
# Add Cloud Resources to Fastify Apps
@@ -42,7 +42,7 @@ You can go ahead and open this new project in your editor of choice. You should
4242

4343
```txt
4444
├── services
45-
│ ├── hello.js
45+
│ ├── api.js
4646
├── node_modules
4747
│ ├── ...
4848
├── .gitignore
@@ -54,18 +54,9 @@ You can go ahead and open this new project in your editor of choice. You should
5454
```
5555

5656
In this structure you'll notice the `servuces` folder. By default, this is where Nitric expects the entrypoint code for your application. However, that's just a convention, we can change that to anything else that suits our needs.
57-
58-
Let's start by replacing the default `hello.js` service with an `app.js` file ready for the Fastify application:
59-
60-
```bash
61-
rm ./services/hello.js
62-
63-
touch ./services/app.js
64-
```
65-
6657
Now, let's add some Fastify code to get things started.
6758

68-
```javascript {{ label: 'services/app.js' }}
59+
```javascript title:services/app.js
6960
import Fastify from 'fastify'
7061
import { http } from '@nitric/sdk'
7162

@@ -94,7 +85,7 @@ nitric start
9485

9586
Your Fastify application will now be running with Nitric acting as a proxy. We can test this in another terminal or web browser.
9687

97-
```bash {{ label: 'terminal' }}
88+
```bash
9889
curl http://localhost:4001
9990
Hello World!
10091
```
@@ -105,7 +96,7 @@ With everything working so far, now is a good time to see how we can add new res
10596

10697
You can update the `app.js` file like so:
10798

108-
```javascript {{ label: 'services/app.js' }}
99+
```javascript title:services/app.js
109100
import Fastify from 'fastify'
110101
import { http, topic } from '@nitric/sdk'
111102

@@ -138,7 +129,7 @@ touch services/worker.js
138129

139130
Add this code to that file:
140131

141-
```javascript {{ label: 'services/worker.js' }}
132+
```javascript title:services/worker.js
142133
import { topic } from '@nitric/sdk'
143134

144135
const sleep = (ms) => new Promise((res) => setTimeout(res, ms))
@@ -173,13 +164,13 @@ To perform the deployment we'll create a `stack`, stacks give Nitric the config
173164

174165
The new stack command can help you create the stack by following prompts.
175166

176-
```bash {{ label: 'terminal' }}
167+
```bash
177168
nitric stack new
178169
```
179170

180171
This command will create a file named `nitric.dev.yaml`, with contents like this:
181172

182-
```yaml {{ label: 'nitric.dev.yaml' }}
173+
```yaml title:nitric.dev.yaml
183174
provider: nitric/[email protected]
184175
region: us-east-1
185176
```

docs/guides/nodejs/graphql.mdx

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ languages:
77
- typescript
88
- javascript
99
published_at: 2022-11-17
10-
updated_at: 2024-03-18
10+
updated_at: 2024-12-27
1111
---
1212

1313
# Building a GraphQL API with Nitric
@@ -56,7 +56,7 @@ The scaffolded project should have the following structure:
5656

5757
```text
5858
+--services/
59-
| +-- hello.ts
59+
| +-- api.ts
6060
+--node_modules/
6161
| ...
6262
+--nitric.yaml
@@ -67,17 +67,9 @@ The scaffolded project should have the following structure:
6767
You can test the project to verify everything is working as expected:
6868

6969
```bash
70-
npm run dev
70+
nitric start
7171
```
7272

73-
<Note>
74-
The `dev` script starts the Nitric Server using `nitric start`, which provides
75-
local interfaces to emulate cloud resources, then runs your services and
76-
allows them to connect.
77-
</Note>
78-
79-
If everything is working as expected you can now delete all files in the `services/` folder, we'll create new services in this guide.
80-
8173
## Build the GraphQL Schema
8274

8375
GraphQL requests are typesafe, and so they require a schema to be defined to validate queries.
@@ -89,10 +81,9 @@ npm install graphql
8981
npm install uuid
9082
```
9183

92-
Create a new file named 'graphql.ts' in the services folder.
9384
We can then import `buildSchema`, and write out the schema.
9485

95-
```typescript
86+
```typescript title:services/api.ts
9687
import { graphql, buildSchema } from 'graphql'
9788
import { v4 as uuid } from 'uuid'
9889

@@ -123,7 +114,7 @@ const schema = buildSchema(`
123114

124115
We will also define a few types to mirror the schema definition.
125116

126-
```typescript
117+
```typescript title:services/api.ts
127118
interface Profile {
128119
pid: string
129120
name: string
@@ -138,7 +129,7 @@ type ProfileInput = Omit<Profile, 'pid'>
138129
139130
Lets define a KV resource for the resolvers get/set data from with some helper functions for serialization.
140131
141-
```typescript
132+
```typescript title:services/api.ts
142133
import { kv } from '@nitric/sdk'
143134

144135
const profiles = kv('profiles').allow('get', 'set')
@@ -171,7 +162,7 @@ async function updateProfiles(profileList) {
171162

172163
We can create a resolver object for use by the graphql handler.
173164

174-
```typescript
165+
```typescript title:services/api.ts
175166
const resolvers = {
176167
createProfile,
177168
fetchProfiles,
@@ -185,7 +176,7 @@ We can then use the KV resource within these services. Each resolver will receiv
185176

186177
## Create a profile
187178

188-
```typescript
179+
```typescript title:services/api.ts
189180
const createProfile = async ({ profile }): Promise<Profile> => {
190181
const profileList = await getProfiles()
191182
profile.pid = uuid()
@@ -197,15 +188,15 @@ const createProfile = async ({ profile }): Promise<Profile> => {
197188

198189
## Get all profiles
199190

200-
```typescript
191+
```typescript title:services/api.ts
201192
const fetchProfiles = async (): Promise<Profile[]> => {
202193
return await getProfiles()
203194
}
204195
```
205196

206197
## Get a profile by its ID
207198

208-
```typescript
199+
```typescript title:services/api.ts
209200
const fetchProfile = async ({ pid }): Promise<Profile> => {
210201
const profileList = await getProfiles()
211202
const profile = profileList.find((profile) => profile.pid === pid)
@@ -219,15 +210,15 @@ We'll define an api to put our handler in. This api will only have one endpoint,
219210

220211
Update the imports to include api and declare the api.
221212

222-
```typescript
213+
```typescript title:services/api.ts
223214
import { api, kv } from '@nitric/sdk'
224215

225216
const profileApi = api('public')
226217
```
227218

228219
Then add the api handler.
229220

230-
```typescript
221+
```typescript title:services/api.ts
231222
import { graphql, buildSchema } from 'graphql'
232223

233224
profileApi.post('/', async (ctx) => {
@@ -249,18 +240,11 @@ Now that you have an API defined with a handler for the GraphQL requests, it's t
249240
Test out your application with the following command:
250241

251242
```bash
252-
npm run dev
243+
nitric start
253244
```
254245

255-
<Note>
256-
The `dev` script in the template starts the Nitric Server using `nitric start`
257-
and runs your services.
258-
</Note>
259-
260246
Once it starts, the application will be able to receive requests via the API port.
261247

262-
Pressing `ctrl + a + k` will end the application.
263-
264248
## GraphQL Queries
265249

266250
We can use cURL, postman or any other HTTP Client to test our application, however it's better if the client has GraphQL support.
@@ -370,31 +354,34 @@ curl --location -X POST \
370354

371355
## Deploy to the cloud
372356

373-
Setup your credentials and any other cloud specific configuration:
357+
At this point, you can deploy what you've built to any of the supported cloud providers. In this example we'll deploy to AWS. Start by setting up your credentials and configuration for the [nitric/aws provider](/providers/pulumi/aws).
374358

375-
- [AWS](/providers/pulumi/aws)
376-
- [Azure](/providers/pulumi/azure)
377-
- [GCP](/providers/pulumi/gcp)
359+
Next, we'll need to create a `stack file` (deployment target). A stack is a deployed instance of an application. You might want separate stacks for each environment, such as stacks for `dev`, `test`, and `prod`. For now, let's start by creating a file for the `dev` stack.
378360

379-
Create a stack - a collection of resources identified in your project which will be deployed.
361+
The `stack new` command below will create a stack named `dev` that uses the `aws` provider.
380362

381363
```bash
382-
nitric stack new
364+
nitric stack new dev aws
383365
```
384366

385-
```
386-
? What should we name this stack? dev
387-
? Which provider do you want to deploy with? aws
388-
? Which region should the stack deploy to? us-east-1
389-
```
367+
Edit the stack file `nitric.dev.yaml` and set your preferred AWS region, for example `us-east-1`.
390368

391-
You can then deploy using the following command:
369+
### AWS
370+
371+
<Note>
372+
You are responsible for staying within the limits of the free tier or any
373+
costs associated with deployment.
374+
</Note>
375+
376+
Let's try deploying the stack with the `up` command:
392377

393378
```bash
394379
nitric up
395380
```
396381

397-
To undeploy run the following command:
382+
When the deployment is complete, go to the relevant cloud console and you'll be able to see and interact with your WebSocket application.
383+
384+
To tear down your application from the cloud, use the `down` command:
398385

399386
```bash
400387
nitric down

0 commit comments

Comments
 (0)