{"id":19656498,"url":"https://github.com/daggerok/nestjs-example","last_synced_at":"2025-02-27T02:20:12.531Z","repository":{"id":40728439,"uuid":"239307586","full_name":"daggerok/nestjs-example","owner":"daggerok","description":"Finally JavaScript has something useful for backend development... All concepts will bd easily understood if you familiar with Angular 2+ ","archived":false,"fork":false,"pushed_at":"2023-01-24T01:20:59.000Z","size":1484,"stargazers_count":0,"open_issues_count":11,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-11T15:38:45.062Z","etag":null,"topics":["github-action","github-action-javascript","github-action-node","github-action-nodejs","github-action-python","github-actions","github-actions-javascript","github-actions-node","github-actions-nodejs","github-actions-python","nest","nestjs","wait-port"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daggerok.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-09T13:16:51.000Z","updated_at":"2021-10-01T16:17:34.000Z","dependencies_parsed_at":"2023-02-13T08:25:15.190Z","dependency_job_id":null,"html_url":"https://github.com/daggerok/nestjs-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daggerok%2Fnestjs-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daggerok%2Fnestjs-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daggerok%2Fnestjs-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daggerok%2Fnestjs-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daggerok","download_url":"https://codeload.github.com/daggerok/nestjs-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240964792,"owners_count":19885807,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["github-action","github-action-javascript","github-action-node","github-action-nodejs","github-action-python","github-actions","github-actions-javascript","github-actions-node","github-actions-nodejs","github-actions-python","nest","nestjs","wait-port"],"created_at":"2024-11-11T15:27:58.433Z","updated_at":"2025-02-27T02:20:12.496Z","avatar_url":"https://github.com/daggerok.png","language":"TypeScript","readme":"# nestjs-example [![CI](https://github.com/daggerok/nestjs-example/workflows/CI/badge.svg)](https://github.com/daggerok/nestjs-example/actions)\nFinally JavaScript has something useful for backend development...\n\nlet's quickly guide its basics....\n\n## create default boilerplate\n\n```bash\nnpx @nestjs/cli new nestjs-example\ncd nestjs-example\nnpm start\n```\n\n## structure\n\n### starting point\n\n_src/main.ts_\n\n```typescript\nimport { NestFactory } from '@nestjs/core';\nimport { AppModule } from './app.module';\n\nasync function bootstrap() {\n  const app = await NestFactory.create(AppModule);\n  await app.listen(3000);\n}\nbootstrap();\n```\n\n### nest app module\n\n_src/app.module.ts_\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { AppController } from './app.controller';\nimport { AppService } from './app.service';\n\n@Module({\n  imports: [],\n  controllers: [AppController],\n  providers: [AppService],\n})\nexport class AppModule {}\n```\n\n### controller\n\n_src/app.controller.ts_\n\n```typescript\nimport { Controller, Get } from '@nestjs/common';\nimport { AppService } from './app.service';\n\n@Controller() // http://127.0.0.1:3000/**\nexport class AppController {\n  constructor(private readonly appService: AppService) {}\n\n  @Get() // -\u003e GET /\n  getHello(): string {\n    return this.appService.getHello();\n  }\n}\n```\n\n### service\n\nthis service will be injected in controller via constructor (see above)\n\n_src/app.service.ts_\n\n```typescript\nimport { Injectable } from '@nestjs/common';\n\n@Injectable()\nexport class AppService {\n  getHello(): string {\n    return 'Hello World!';\n  }\n}\n```\n\n## testing\n\nas we can see, how we have only one endpoint: `GET /` which should hello:\n\n```bash\nhttp :3000\n```\n\nresponse\n\n```http request\nHTTP/1.1 200 OK\nConnection: keep-alive\nContent-Length: 12\nContent-Type: text/html; charset=utf-8\nDate: Sun, 09 Feb 2020 13:13:44 GMT\nETag: W/\"c-Lve95gjOVATpfV8EL5X4nxwjKHE\"\nX-Powered-By: Express\n\nHello World!\n```\n\n## implement a feature\n\nif you familiar with ng cli (@angular/cli from Angular framework) it would be very similar!\n\n### new module\n\nlet's implement Maksimko's module:\n\n```bash\nnpx @nestjs/cli generate module maksimko\n#CREATE /src/maksimko/maksimko.module.ts (85 bytes)\n#UPDATE /src/app.module.ts (324 bytes)\n```\n\nverify main module has been updated:\n\n_src/app.module.ts_\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { AppController } from './app.controller';\nimport { AppService } from './app.service';\nimport { MaksimkoModule } from './maksimko/maksimko.module';\n\n@Module({\n  imports: [MaksimkoModule],\n  controllers: [AppController],\n  providers: [AppService],\n})\nexport class AppModule {}\n```\n\nas you can see, now imports array is not empty and contains created `MaksimkoModule`:\n\n_src/maksimko/maksimko.module.ts_\n\n```typescript\nimport { Module } from '@nestjs/common';\n\n@Module({})\nexport class MaksimkoModule {}\n```\n\n### new controller\n\nsimilarly, let's generate new controller\n\n```bash\nnpx @nestjs/cli generate controller maksimko\n#CREATE /src/maksimko/maksimko.controller.spec.ts (507 bytes)\n#CREATE /src/maksimko/maksimko.controller.ts (105 bytes)\n#UPDATE /src/maksimko/maksimko.module.ts (182 bytes)\n```\n\nnow maksimko module should be updated:\n\n_src/maksimko/maksimko.module.ts_\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { MaksimkoController } from './maksimko.controller';\n\n@Module({\n  controllers: [MaksimkoController]\n})\nexport class MaksimkoModule {}\n```\n\nand new controller created:\n\n_src/maksimko/maksimko.controller.ts_\n\n```typescript\nimport { Controller } from '@nestjs/common';\n\n@Controller('maksimko') // http://127.0.0.21:3000/maksimko/**\nexport class MaksimkoController {}\n```\n\n### new service\n\nfinally let's similarly create new service:\n\n```bash\nnpx @nestjs/cli generate service maksimko\n#CREATE /src/maksimko/maksimko.service.spec.ts (474 bytes)\n#CREATE /src/maksimko/maksimko.service.ts (92 bytes)\n#UPDATE /src/maksimko/maksimko.module.ts (268 bytes)\n```\n\n_src/maksimko/maksimko.module.ts_\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { MaksimkoController } from './maksimko.controller';\nimport { MaksimkoService } from './maksimko.service';\n\n@Module({\n  controllers: [MaksimkoController],\n  providers: [MaksimkoService]\n})\nexport class MaksimkoModule {}\n```\n\n_src/maksimko/maksimko.service.ts_\n\n```typescript\nimport { Injectable } from '@nestjs/common';\n\n@Injectable()\nexport class MaksimkoService {}\n```\n\n### implementation\n\n_service_\n\n```typescript\nimport { Injectable } from '@nestjs/common';\n\n@Injectable()\nexport class MaksimkoService {\n  wtf(what: string): string {\n    return `O.o ${what}?`;\n  }\n}\n```\n\n_controller_\n\n```typescript\nimport { Controller, Param, Post } from '@nestjs/common';\nimport { MaksimkoService } from './maksimko.service';\n\n@Controller('maksimko')\nexport class MaksimkoController {\n\n  constructor(private maksimkoService: MaksimkoService) {}\n\n  @Post('/wtf/:what')\n  async wtf(@Param('what') what: string): Promise\u003cstring\u003e {\n    return this.maksimkoService.wtf(what);\n  }\n}\n```\n\n### testing\n\n```bash\nhttp post :3000/maksimko/wtf/ololo\n```\n\noutput:\n\n```http\nHTTP/1.1 201 Created\nConnection: keep-alive\nContent-Length: 10\nContent-Type: text/html; charset=utf-8\nDate: Sun, 09 Feb 2020 15:22:17 GMT\nETag: W/\"a-PbhLKehORdMno9Pz2s34zAbmS0I\"\nX-Powered-By: Express\n\nO.o ololo?\n```\n\n## License\n\nNest is [MIT licensed](LICENSE).\n\n## resoiurces\n\n* [Official documentation](https://docs.nestjs.com/)\n* [project GitHub repo: nestjs/nest](https://github.com/nestjs/nest)\n* [YouTube: NestJS For Absolute Beginners](youtube.com/watch?v=4RkMAt8-u8g)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaggerok%2Fnestjs-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaggerok%2Fnestjs-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaggerok%2Fnestjs-example/lists"}