open-index/open-npm huggingface dataset:
npm package: @harperdb/nestjs
Description: A HarperDB Component for running Next.js apps.
Author: HarperDB
Latest version: 0.1.1

# @harperdb/nestjs

A [HarperDB Component](https://docs.harperdb.io/docs/developers/components) for running and developing NestJS apps.

![NPM Version](https://img.shields.io/npm/v/%40harperdb%2Fnestjs)

Most Next.js features are supported as we rely on the NestJS Server provided by NestJS to run your application.

## Usage

> [!NOTE]
> This guide assumes you're already familiar with [HarperDb Components](https://docs.harperdb.io/docs/developers/components). Please review the documentation, or check out the HarperDB [Next.js Example](https://github.com/HarperDB/nestjs-example) for more information.

1. Install:

```sh
npm install @harperdb/nestjs
```

2. Add to `config.yaml`:

```yaml
'@harperdb/nestjs':
  package: '@harperdb/nestjs'
  files: '/*'
```

3. Run your app with HarperDB:

```sh
harperdb run nestjs-app
```

4. Within any server side code paths, you can use [HarperDB Globals](https://docs.harperdb.io/docs/technical-details/reference/globals) after importing the HarperDB package:

```js
// app/actions.js
'use server';

import('harperdb');

export async function listDogs() {
	const dogs = [];
	for await (const dog of tables.Dog.search()) {
		dogs.push({ id: dog.id, name: dog.name });
	}
	return dogs;
}

export async function getDog(id) {
	return tables.Dog.get(id);
}
```

```js
// app/dogs/[id]/page.jsx
import { getDog, listDogs } from '@/app/actions';

export async function generateStaticParams() {
	const dogs = await listDogs();

	return dogs;
}

export default async function Dog({ params }) {
	const dog = await getDog(params.id);

	return (
		<section>
			<h1>{dog.name}</h1>
			<p>Breed: {dog.get('breed')}</p>
			<p>Woof!</p>
		</section>
	);
}
```