Skip to content

Commit bc7385e

Browse files
authored
docs(examples/node): update example to run as expected (#393)
1 parent 3f02e3b commit bc7385e

File tree

7 files changed

+783
-37
lines changed

7 files changed

+783
-37
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,5 @@ docs/dist
116116
src/api-version.ts
117117

118118
*.DS_Store
119+
120+
playwright-report/

Node.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Node & Viam's TypeScript SDK
1+
# Node.js & Viam's TypeScript SDK
22

3-
This document contains detailed instructions on including Viam in your Node project. For a runnable example, see the [examples directory](/examples/node/).
3+
This document contains detailed instructions on including Viam in your Node.js project. For a runnable example, see the [examples directory](/examples/node/).
44

55
## Requirements
66

7-
This document assumes you already have Node installed. If not, follow the [instructions](https://nodejs.org/en/learn/getting-started/how-to-install-nodejs) provided by Node.
7+
This document assumes you already have Node.js >= version 20 installed. If not, follow the [instructions](https://nodejs.org/en/learn/getting-started/how-to-install-nodejs) provided by Node.js.
88

99
### Dependencies
1010

@@ -19,25 +19,25 @@ You can use either Yarn or NPM to install the dependencies. This document will u
1919

2020
### Polyfills
2121

22-
Using the SDK with Node also requires the use of some polyfills. In your application's entrypoint (`main.ts`, `index.ts`, or something similar), you will need to register those polyfills:
22+
Using the SDK with Node.js also requires the use of some polyfills. In your application's entrypoint (`main.ts`, `index.ts`, or something similar), you will need to register those polyfills:
2323

2424
```ts
2525
// main.ts
2626

27-
import wrtc = require('node-datachannel/polyfill');
27+
const wrtc = require('node-datachannel/polyfill');
2828
for (const key in wrtc) {
2929
(global as any)[key] = (wrtc as any)[key];
3030
}
3131
```
3232

3333
### Transport
3434

35-
Communicating with your Viam machine in Node requires the use of a custom transport. In your app's entrypoint, you will also need to register the custom transport:
35+
Communicating with your Viam machine in Node.js requires the use of a custom transport. In your app's entrypoint, you will also need to register the custom transport:
3636

3737
```ts
3838
// main.ts
3939

40-
import connectNode = require('@connectrpc/connect-node');
40+
const connectNode = require('@connectrpc/connect-node');
4141
globalThis.VIAM = {
4242
GRPC_TRANSPORT_FACTORY: (opts: any) =>
4343
connectNode.createGrpcTransport({ httpVersion: '2', ...opts }),
@@ -51,9 +51,9 @@ To use the SDK, you can use similar instructions to those found on the [document
5151
```ts
5252
// main.ts
5353

54-
import VIAM = require('@viamrobotics/sdk');
55-
import wrtc = require('node-datachannel/polyfill');
56-
import connectNode = require('@connectrpc/connect-node');
54+
const VIAM = require('@viamrobotics/sdk');
55+
const wrtc = require('node-datachannel/polyfill');
56+
const connectNode = require('@connectrpc/connect-node');
5757
globalThis.VIAM = {
5858
GRPC_TRANSPORT_FACTORY: (opts: any) =>
5959
connectNode.createGrpcTransport({ httpVersion: '2', ...opts }),

e2e/tests/connect-and-status.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ test('check resource names and multiple statuses', async ({ page }) => {
77
const resourceNames = page
88
.getByTestId('resource-names')
99
.getByTestId('resource-name');
10-
await expect(resourceNames).toHaveCount(4);
10+
await expect(resourceNames).toHaveCount(3);
1111
await expect(resourceNames.getByText('base1')).toHaveCount(1);
1212
await expect(resourceNames.getByText('servo1')).toHaveCount(1);
13-
await expect(resourceNames.getByText('builtin')).toHaveCount(2);
13+
await expect(resourceNames.getByText('builtin')).toHaveCount(1);
1414

15-
// 3 status iterations * 4 resource names (see main.ts for loop)
15+
// 3 status iterations * 3 resource names (see main.ts for loop)
1616
const statuses = page.getByTestId('statuses').getByTestId('status');
17-
await expect(statuses).toHaveCount(12);
17+
await expect(statuses).toHaveCount(9);
1818
});

examples/node/README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Viam SDK Quickstart - Node
1+
# Viam SDK Quickstart - Node.js
22

33
This example demonstrates how to connect to a machine using Node.js.
44

55
## Usage
66

7-
You must have a `.env` file in this directory with the following connection info which can be easily found in the TypeScript code sample for your machine.
7+
You must have a `.env` file in this directory with the following connection info which can be easily found in the TypeScript code sample for your machine. Use the `authEntity` value from the Code Sample as the `API_KEY_ID` and the `payload` value as the `API_KEY`.
88

99
```
1010
HOST="<HOST>"
@@ -42,18 +42,18 @@ The `main.ts` file was updated to include the following polyfills and updates:
4242
- WebRTC Polyfills:
4343

4444
```js
45-
import wrtc = require('node-datachannel/polyfill');
46-
for (const key in wrtc) {
47-
(global as any)[key] = (wrtc as any)[key];
48-
}
45+
const wrtc = require('node-datachannel/polyfill');
46+
for (const key in wrtc) {
47+
(global as any)[key] = (wrtc as any)[key];
48+
}
4949
```
5050

5151
- GRPC connection configuration
5252
```js
53-
import VIAM = require('@viamrobotics/sdk');
54-
globalThis.VIAM = {
55-
// @ts-ignore
56-
GRPC_TRANSPORT_FACTORY: (opts: any) =>
57-
connectNode.createGrpcTransport({ httpVersion: '2', ...opts }),
58-
};
53+
const VIAM = require('@viamrobotics/sdk');
54+
globalThis.VIAM = {
55+
// @ts-ignore
56+
GRPC_TRANSPORT_FACTORY: (opts: any) =>
57+
connectNode.createGrpcTransport({ httpVersion: '2', ...opts }),
58+
};
5959
```

0 commit comments

Comments
 (0)