You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 20, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: docs/guides/nodejs/expressjs.mdx
+7-15Lines changed: 7 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ languages:
7
7
- typescript
8
8
- javascript
9
9
published_at: 2023-07-10
10
-
updated_at: 2024-03-18
10
+
updated_at: 2024-12-27
11
11
---
12
12
13
13
# 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
42
42
43
43
```txt
44
44
├── services
45
-
│ ├── hello.js
45
+
│ ├── api.js
46
46
├── node_modules
47
47
│ ├── ...
48
48
├── .gitignore
@@ -55,17 +55,9 @@ You can go ahead and open this new project in your editor of choice. You should
55
55
56
56
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.
57
57
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
-
66
58
Now, let's add some express code to get things started.
67
59
68
-
```javascript{{ label: 'services/app.js' }}
60
+
```javascript title:services/api.js
69
61
importexpressfrom'express'
70
62
import { http } from'@nitric/sdk'
71
63
constapp=express()
@@ -100,9 +92,9 @@ Hello World!
100
92
101
93
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.
Copy file name to clipboardExpand all lines: docs/guides/nodejs/fastify.mdx
+8-17Lines changed: 8 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ languages:
7
7
- typescript
8
8
- javascript
9
9
published_at: 2023-07-12
10
-
updated_at: 2024-03-18
10
+
updated_at: 2024-12-27
11
11
---
12
12
13
13
# 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
42
42
43
43
```txt
44
44
├── services
45
-
│ ├── hello.js
45
+
│ ├── api.js
46
46
├── node_modules
47
47
│ ├── ...
48
48
├── .gitignore
@@ -54,18 +54,9 @@ You can go ahead and open this new project in your editor of choice. You should
54
54
```
55
55
56
56
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
-
66
57
Now, let's add some Fastify code to get things started.
67
58
68
-
```javascript{{ label: 'services/app.js' }}
59
+
```javascript title:services/app.js
69
60
importFastifyfrom'fastify'
70
61
import { http } from'@nitric/sdk'
71
62
@@ -94,7 +85,7 @@ nitric start
94
85
95
86
Your Fastify application will now be running with Nitric acting as a proxy. We can test this in another terminal or web browser.
96
87
97
-
```bash {{ label: 'terminal' }}
88
+
```bash
98
89
curl http://localhost:4001
99
90
Hello World!
100
91
```
@@ -105,7 +96,7 @@ With everything working so far, now is a good time to see how we can add new res
@@ -219,15 +210,15 @@ We'll define an api to put our handler in. This api will only have one endpoint,
219
210
220
211
Update the imports to include api and declare the api.
221
212
222
-
```typescript
213
+
```typescript title:services/api.ts
223
214
import { api, kv } from'@nitric/sdk'
224
215
225
216
const profileApi =api('public')
226
217
```
227
218
228
219
Then add the api handler.
229
220
230
-
```typescript
221
+
```typescript title:services/api.ts
231
222
import { graphql, buildSchema } from'graphql'
232
223
233
224
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
249
240
Test out your application with the following command:
250
241
251
242
```bash
252
-
npm run dev
243
+
nitric start
253
244
```
254
245
255
-
<Note>
256
-
The `dev` script in the template starts the Nitric Server using `nitric start`
257
-
and runs your services.
258
-
</Note>
259
-
260
246
Once it starts, the application will be able to receive requests via the API port.
261
247
262
-
Pressing `ctrl + a + k` will end the application.
263
-
264
248
## GraphQL Queries
265
249
266
250
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 \
370
354
371
355
## Deploy to the cloud
372
356
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).
374
358
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.
378
360
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.
380
362
381
363
```bash
382
-
nitric stack new
364
+
nitric stack new dev aws
383
365
```
384
366
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`.
390
368
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:
392
377
393
378
```bash
394
379
nitric up
395
380
```
396
381
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:
0 commit comments