Skip to content

Commit

Permalink
Update-dependencies-and-docs (#9)
Browse files Browse the repository at this point in the history
* chore(security): Update Next.js to resolve dependabot report

* docs: List InfluxDB credential prereqs

- Add links for InfluxDB prereqs. We either overlooked this or expected to create the buckets from example app.

* docs: Improve README.

* Update README.md

Co-authored-by: Scott Anderson <[email protected]>

---------

Co-authored-by: Scott Anderson <[email protected]>
  • Loading branch information
jstirnaman and sanderson authored May 15, 2024
1 parent eff2565 commit 2514143
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 73 deletions.
107 changes: 75 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# iot-api-js

This example project provides a Node.js server-side REST API that interacts with InfluxDB.
It is an adaptation of [InfluxData IoT Center](https://github.com/bonitoo-io/iot-center-v2), simplified to accompany the InfluxData IoT Starter tutorial.
You can consume this API with the example [iot-api-ui](https://github.com/influxdata/iot-api-ui) React frontend.
The project uses the [Next.js](https://nextjs.org/) framework and the InfluxDB API client library for JavaScript.
This example project provides a Node.js REST API server that interacts with the InfluxDB v2 HTTP API.
The project uses the [Next.js](https://nextjs.org/) framework and the [InfluxDB v2 API client library for JavaScript](https://docs.influxdata.com/influxdb/v2/api-guide/client-libraries/nodejs/) to demonstrate how to build an app that collects, stores, and queries IoT device data.
After you have set up and run your `iot-api-js` API server, you can consume your API using the [iot-api-ui](https://github.com/influxdata/iot-api-ui) standalone React frontend.

## Features

Expand All @@ -14,40 +13,39 @@ This application demonstrates how you can use InfluxDB client libraries to do th
- Write and query telemetry data in InfluxDB.
- Generate data visualizations with the InfluxDB Giraffe library.

## Get started
## Tutorial and support

To learn how to create the app from scratch, follow the IoT Starter tutorial.
To run the app, do the following:
To learn how to build this app from scratch, follow the [InfluxDB v2 OSS tutorial](https://docs.influxdata.com/influxdb/v2/api-guide/tutorials/nodejs/) or [InfluxDB Cloud tutorial](https://docs.influxdata.com/influxdb/cloud/api-guide/tutorials/nodejs/).
The app is an adaptation of [InfluxData IoT Center](https://github.com/bonitoo-io/iot-center-v2), simplified to accompany the IoT Starter tutorial.

1. If you don't already have an InfluxDB instance, [create an InfluxDB Cloud account](https://www.influxdata.com/products/influxdb-cloud/) or [install InfluxDB OSS](https://www.influxdata.com/products/influxdb/).
2. Clone this repository to your machine.
3. Change to the directory--for example, enter the following code into the terminal:
For help, refer to the tutorials and InfluxDB documentation or use the following resources:

```bash
cd ./iot-api-js
```
- [InfluxData Community](https://community.influxdata.com/)
- [InfluxDB Community Slack](https://influxdata.com/slack)

4. If you haven't already, follow the [Node.js installation instructions](https://nodejs.org/) to install `node` for your operating system.
5. To check the installed `node` version, enter the following code into your terminal:
To report a problem, submit an issue to this repo or to the [`influxdata/docs-v2` repo](https://github.com/influxdata/docs-v2/issues).

```bash
node --version
```
## Get started

6. Follow the [Yarn installation instructions](https://yarnpkg.com/getting-started/install#nodejs-1610-1) to install the `yarn` package manager for your version of Node.js.
7. To check the installed `yarn` version, enter the following code into your terminal:
### Set up InfluxDB prerequisites

```bash
yarn --version
```
Follow the tutorial instructions to setup your InfluxDB organization, API token, and buckets:

8. With `yarn` installed, enter the following code into your terminal to install the project dependencies:
- [Set up InfluxDB OSS v2 prerequisites](https://docs.influxdata.com/influxdb/v2/api-guide/tutorials/nodejs/#set-up-influxdb)
- [Set up InfluxDB Cloud v2 prerequisites](https://docs.influxdata.com/influxdb/cloud/api-guide/tutorials/nodejs/#set-up-influxdb)

Next, [clone and run the API server](#clone-and-run-the-api-server).

### Clone and run the API server

1. Clone this repository to your machine.
2. Change to the directory--for example, enter the following command in your terminal:

```bash
yarn
cd ./iot-api-js
```

9. Add a `./.env.local` file that contains the following configuration variables:
3. Add a `.env.local` file that contains the following configuration variables:

```bash
# Local environment secrets
Expand All @@ -60,20 +58,65 @@ To run the app, do the following:

- **`INFLUXDB_ALL_ACCESS_TOKEN`** with your InfluxDB **All Access** token.
- **`INFLUXDB_ORG_ID`** with your InfluxDB organization ID.

10. To start the application in **development** mode, enter the following code into the terminal:

4. If you need to adjust the default URL or bucket names to match your InfluxDB instance, edit the settings in `.env.development` or set them in `.env.local` (to override `.env.development`).
5. If you haven't already, follow the [Node.js installation instructions](https://nodejs.org/) to install `node` for your operating system.
6. To check the installed `node` version, enter the following command in your terminal:

```bash
node --version
```

7. Follow the [Yarn installation instructions](https://yarnpkg.com/getting-started/install#nodejs-1610-1) to install the `yarn` package manager for your version of Node.js.
8. To check the installed `yarn` version, enter the following command in your terminal:

```bash
yarn --version
```

9. Run `yarn` to install the project dependencies:

```bash
yarn
```

10. In your terminal, enter the following command to start the application in **development** mode:

```bash
yarn dev -p 3001
yarn dev -p 5200
```

The application server starts with the following output:

```bash
> dev
> next dev
ready - started server on 0.0.0.0:3001, url: http://localhost:3001
ready - started server on 0.0.0.0:5200, url: http://localhost:5200
```

11. In your browser, visit <http://localhost:3001/devices> to view the API output.
12. Next, you can use the example [iot-api-ui](https://github.com/influxdata/iot-api-ui) React frontend to interact with the API.
11. In your browser, visit <http://localhost:5200/api/devices> to view the API server output.

12. _Optional_: Run the [iot-api-ui](https://github.com/influxdata/iot-api-ui) React frontend to interact with your IoT Starter API server.

## Troubleshoot

### Error: could not find bucket

```json
{"error":"failed to load data: HttpError: failed to initialize execute state: could not find bucket \"iot_center_devices\""}
```

Solution: [create buckets](#set-up-influxdb-prerequisites) or adjust the defaults in `.env.development` to match your InfluxDB instance.

## Learn More

### InfluxDB

- Develop with the InfluxDB API for [OSS v2](https://docs.influxdata.com/influxdb/v2/api-guide/) or [Cloud v2](https://docs.influxdata.com/influxdb/cloud/api-guide/).

### Next.js

To learn more about Next.js, see following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"dependencies": {
"@influxdata/influxdb-client": "^1.24.0",
"@influxdata/influxdb-client-apis": "^1.24.0",
"next": "latest",
"react": "17.0.2",
"react-dom": "17.0.2"
"next": "^14.2.3",
"postcss": "^8.4.31",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"resolutions": {
"postcss": "^8.4.31"
Expand Down
73 changes: 35 additions & 38 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@


"@influxdata/influxdb-client-apis@^1.24.0":
version "1.26.0"
resolved "https://registry.yarnpkg.com/@influxdata/influxdb-client-apis/-/influxdb-client-apis-1.26.0.tgz#ad2b127440fd6bf33f402446c7638d35da3bbdf2"
integrity sha512-3QD58zoZ6GS53R3avKrial5SsowhW9D19BUiJWpRKOaOIK5+L0gXKHydrYhwj7cUa7sC2Q3yOdosmOTp9+YQMg==
version "1.33.2"
resolved "https://registry.yarnpkg.com/@influxdata/influxdb-client-apis/-/influxdb-client-apis-1.33.2.tgz#792f4ae3930588cee6ac20c1192bf8c38dbd0765"
integrity sha512-W6x9TOAQ3AUx0RBCrCibDhSvMqN50lxJmElc3rHn7+R/9Zi35oczu8r9YMkyNlzWnksu+dcyKr8/xLv28Ot4hw==

"@influxdata/influxdb-client@^1.24.0":
version "1.26.0"
resolved "https://registry.yarnpkg.com/@influxdata/influxdb-client/-/influxdb-client-1.26.0.tgz#742ecc498869362a6f0e7e4d1ef4c975e91b935e"
integrity sha512-outv3/ODQGPoGTxXaFJC/s1gJwcOjATTfObG4/z7sjKJYyHMYhjxxqhx16yjlpFwkTx/VUYleWkkbM3HMuUBgg==
version "1.33.2"
resolved "https://registry.yarnpkg.com/@influxdata/influxdb-client/-/influxdb-client-1.33.2.tgz#c68cfcf592e4e042361003143fbab99461410172"
integrity sha512-RT5SxH+grHAazo/YK3UTuWK/frPWRM0N7vkrCUyqVprDgQzlLP+bSK4ak2Jv3QVF/pazTnsxWjvtKZdwskV5Xw==

"@next/[email protected]":
version "14.2.3"
Expand Down Expand Up @@ -109,10 +109,10 @@ loose-envify@^1.1.0:
dependencies:
js-tokens "^3.0.0 || ^4.0.0"

nanoid@^3.3.6:
version "3.3.6"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.6.tgz#443380c856d6e9f9824267d960b4236ad583ea4c"
integrity sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==
nanoid@^3.3.7:
version "3.3.7"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.7.tgz#d0c301a691bc8d54efa0a2226ccf3fe2fd656bd8"
integrity sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==

next@latest:
version "14.2.3"
Expand Down Expand Up @@ -143,48 +143,45 @@ object-assign@^4.1.1:
integrity sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==

picocolors@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c"
integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==
version "1.0.1"
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.1.tgz#a8ad579b571952f0e5d25892de5445bcfe25aaa1"
integrity sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==

[email protected], postcss@^8.4.31:
version "8.4.31"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.31.tgz#92b451050a9f914da6755af352bdc0192508656d"
integrity sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==
version "8.4.38"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.38.tgz#b387d533baf2054288e337066d81c6bee9db9e0e"
integrity sha512-Wglpdk03BSfXkHoQa3b/oulrotAkwrlLDRSOb9D0bN86FdRyE9lppSp33aHNPgBa0JKCoB+drFLZkQoRRYae5A==
dependencies:
nanoid "^3.3.6"
nanoid "^3.3.7"
picocolors "^1.0.0"
source-map-js "^1.0.2"
source-map-js "^1.2.0"

react-dom@17.0.2:
version "17.0.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.2.tgz#ecffb6845e3ad8dbfcdc498f0d0a939736502c23"
integrity sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA==
react-dom@^18.2.0:
version "18.3.1"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.3.1.tgz#c2265d79511b57d479b3dd3fdfa51536494c5cb4"
integrity sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
scheduler "^0.20.2"
scheduler "^0.23.2"

react@17.0.2:
version "17.0.2"
resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037"
integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==
react@^18.2.0:
version "18.3.1"
resolved "https://registry.yarnpkg.com/react/-/react-18.3.1.tgz#49ab892009c53933625bd16b2533fc754cab2891"
integrity sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"

scheduler@^0.20.2:
version "0.20.2"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.20.2.tgz#4baee39436e34aa93b4874bddcbf0fe8b8b50e91"
integrity sha512-2eWfGgAqqWFGqtdMmcL5zCMK1U8KlXv8SQFGglL3CEtd0aDVDWgeF/YoCmvln55m5zSk3J/20hTaSBeSObsQDQ==
scheduler@^0.23.2:
version "0.23.2"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.23.2.tgz#414ba64a3b282892e944cf2108ecc078d115cdc3"
integrity sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"

source-map-js@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c"
integrity sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==
source-map-js@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.2.0.tgz#16b809c162517b5b8c3e7dcd315a2a5c2612b2af"
integrity sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==

streamsearch@^1.1.0:
version "1.1.0"
Expand Down

0 comments on commit 2514143

Please sign in to comment.