Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hebertcisco/nestjs-techniques-undici

Undici module example: https://github.com/hebertcisco/nestjs-undici
https://github.com/hebertcisco/nestjs-techniques-undici

nestjs nestjs-boilerplate nestjs-undici typescript undici

Last synced: 1 day ago
JSON representation

Undici module example: https://github.com/hebertcisco/nestjs-undici

Awesome Lists containing this project

README

        

[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/hebertcisco/nestjs-techniques-undici)

[![🚀 Build](https://github.com/hebertcisco/nestjs-techniques-undici/actions/workflows/build.yml/badge.svg)](https://github.com/hebertcisco/nestjs-techniques-undici/actions/workflows/build.yml)

# Basic documentation

### Usage example:

```ts
// app.module.ts
import { Module } from '@nestjs/common';
import { HttpModule } from 'nestjs-undici';

import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
imports: [
HttpModule.register({
headers: {
'my-header': `foo-bar`,
},
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
```

```ts
// app.service.ts
import { lastValueFrom } from 'rxjs';

import { Injectable } from '@nestjs/common';
import { HttpService } from 'nestjs-undici';

@Injectable()
export class AppService {
constructor(private httpService: HttpService) {}
public fetchExternalInfo = async () => {
const baseURL = 'https://api.github.com';
try {
const result = this.httpService.request(
`${baseURL}/repos/hebertcisco/undici`,
);

const response = await lastValueFrom(result);

return response.body.json();
} catch (error) {
throw error;
}
};
}
```

## Runing the application with docker

### Run as dev

```sh
docker-compose up dev
```

### Run as prod

```sh
docker-compose up -d prod
```

## Runing the application with npm scrips

```sh
npm install && npm run build
```

```sh
npm run prepare:enviroment
```

### Run as dev

```sh
npm run dev
```

or

```sh
npm run dev:test
```

### Run as prod

```sh
npm run start
```

or

```sh
npm run start:prod
```