{"id":23882090,"url":"https://github.com/ahsansoftengineer/nest_best_practice","last_synced_at":"2026-02-28T13:31:17.737Z","repository":{"id":39533455,"uuid":"507004493","full_name":"ahsansoftengineer/NEST_Best_Practice","owner":"ahsansoftengineer","description":null,"archived":false,"fork":false,"pushed_at":"2022-12-17T02:38:23.000Z","size":4034,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-12T03:33:41.127Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahsansoftengineer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-24T12:35:55.000Z","updated_at":"2023-07-11T07:48:43.000Z","dependencies_parsed_at":"2023-01-29T16:31:38.905Z","dependency_job_id":null,"html_url":"https://github.com/ahsansoftengineer/NEST_Best_Practice","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ahsansoftengineer/NEST_Best_Practice","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahsansoftengineer%2FNEST_Best_Practice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahsansoftengineer%2FNEST_Best_Practice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahsansoftengineer%2FNEST_Best_Practice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahsansoftengineer%2FNEST_Best_Practice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahsansoftengineer","download_url":"https://codeload.github.com/ahsansoftengineer/NEST_Best_Practice/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahsansoftengineer%2FNEST_Best_Practice/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29935355,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-28T13:16:57.922Z","status":"ssl_error","status_checked_at":"2026-02-28T13:11:15.149Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2025-01-04T02:37:50.076Z","updated_at":"2026-02-28T13:31:17.694Z","avatar_url":"https://github.com/ahsansoftengineer.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NEST JS SETTINGS\n## STARTING APPLICATION\n### KNOWLEDGE\n#### DIFFERENCE PNPM, NPM, YARN\n* PNPM: PNPM is 3 times faster and more efficient than NPM. With both cold and hot cache, PNPM is faster than Yarn. Pnpm simply links files from the global store, while yarn copies files from its cache. Package versions are never saved more than once on a disk.\n```shell\nnpm install -g pnpm // Fast installation\nnpm i -g @nestjs/cli\nnpm i --location=global @nestjs/cli\nnpm i --save @sendgrid/mail\n\nnpm cache clean --force\nrm package-lock.json\nnest new project-name\n```\n#### CONFIG NPM GLOBAL\n```shell\nnpm config set timeout 6000000\nnpm config set fetch-retries 3\nnpm config set cache-min 3600\nnpm config set fetch-retry-maxtimeout 600000\n```\n#### CONFIG GIT GLOBAL\n```shell\ngit config --global user.email \"you@example.com\"\ngit config --global user.name \"Your Name\"\n```\n#### SETTING ENV\n* * File -\u003e .env, .env.prod, .env.dev\n* * File -\u003e AppModule.ts\n* * File -\u003e ConfigConfig.ts\n```java\n// To Set the Environment in Power Shell use the following command to change the ENV\n$env:ENVIRONMENT = 'STAGE'\n// and then run the following command\nnpm run start:dev\n// TODO: NOTE some how it is not working\n```\n#### QUERY\n* * Don't know the use case of dotenv cli\n#### DEPENDENCIES\n```java\nnpm i --save @nestjs/config @nestjs/typeorm @nestjs/passport  @nestjs/jwt @nestjs/throttler @nestjs/serve-static @nestjs-modules/mailer @casl/ability nodemailer typeorm mysql2 express-session bcrypt class-validator class-transformer  passport passport-local  passport-jwt typeorm-extension joi bcrypt helmet csurf cpx argon2 dotenv-parse dotenv-cli passport-google-oauth20 \n```\n#### DEV DEPENDENCIES\n```java\nnpm i -D @types/node @types/bcrypt @types/passport-local @types/passport-jwt @types/express-session  @types/joi @types/bcrypt @types/multer @types/express-session @types/passport-google-oauth20  webpack-node-externals run-script-webpack-plugin webpack  \n```\n#### LEGACY COMMAND / FORCE\n```java\nnpm install --save-dev typeorm-seeder --legacy-peer-deps\n```\n#### HOT RELOADING\n* * Filename =\u003e webpack-hmr.config.js\n```javascript\n/* eslint-disable @typescript-eslint/no-var-requires */\nconst nodeExternals = require('webpack-node-externals');\nconst { RunScriptWebpackPlugin } = require('run-script-webpack-plugin');\n\nmodule.exports = function (options, webpack) {\n  return {\n    ...options,\n    entry: ['webpack/hot/poll?100', options.entry],\n    externals: [\n      nodeExternals({\n        allowlist: ['webpack/hot/poll?100'],\n      }),\n    ],\n    plugins: [\n      ...options.plugins,\n      new webpack.HotModuleReplacementPlugin(),\n      new webpack.WatchIgnorePlugin({\n        paths: [/\\.js$/, /\\.d\\.ts$/],\n      }),\n      new RunScriptWebpackPlugin({ name: options.output.filename }),\n    ],\n  };\n};\n```\n### TYPEORM\n#### CREATE AN CHILD ENTITY\n\n* * 1 Create Entity\n```java\n@ChildEntity() // @Entity() for Simple\nexport class Parent extends Person{\n  @ManyToMany(() =\u003e Student, (a) =\u003e a.id, {\n    cascade: true,\n  })\n  @JoinTable({name: 'parent_student'})\n  students: Student[]\n}\n```\n* * 2 Registering to Module\n```java\n@Module({\n  imports: [\n    TypeOrmModule.forFeature([Parent]), // .forFeature Not .forRoot\n    PersonModule // TableInheritance\n  ],\n  controllers: [ParentController],\n  providers: [ParentService]\n})\nexport class ParentModule {}\n```\n* * 3 Adding to Entity array\n```typescript\nexport const entities = [\n  BetaModel, // Also the Base Entity Model is Required for defination\n  Person, // Table Inheritance Entity Model is also Required\n  Parent // The Entity\n];\n```\n* * 4 Import this Module to Parent Module\n```java\n@Module({\n  imports: [\n    PersonModule, \n    ParentModule, \n  ]\n})\nexport class FeatureSchoolModule { }\n```\n* * 5 Import Parent Module to App Module\n```java\n@Module({\n  imports: [\n    TypeOrmModule.forRoot({\n      type: ENV.DB_TYPE,\n      host: ENV.DB_HOST,\n      port: ENV.DB_PORT,\n      username: ENV.DB_USERNAME,\n      password: ENV.DB_PASSWORD,\n      database: ENV.DB_DATABASE,\n      entities: [...baseEntities, ...entities], // STEP 2\n      retryDelay: 10000,\n      retryAttempts: 2, \n      logging: true,// ['query', 'error'] /* true, 'all', new MyCustomLogger()*/,\n      // logger: 'advanced-console' // default\n      synchronize: ENV.DB_SYNC,\n      dropSchema: ENV.DB_DROP,\n      // subscribers: [],\n      // migrations: [],\n    }),\n    FeatureSchoolModule,\n  ],\n})\nexport class AppModule {}\n```\n#### TYPEORM MIGIRATION\n* Packages to Install\n```java\nnpm i typeorm\nnpm i -D typeorm-seeder --legacy-peer-deps\n```\n* package.json\n```json\n{\n    \"scripts\": {\n      \"seed:config\": \"ts-node ./node_modules/typeorm-seeding/dist/cli.js config -n dist/core/config/ConfigTypeOrmMigration.js\",\n      \"seed:run\": \"ts-node ./node_modules/typeorm-seeding/dist/cli.js seed -n dist/core/config/typeorm.config-migrations.ts\"\n    }\n}\n```\n* To Customize the Seed Location \n```yaml\nTYPEORM_SEEDING_FACTORIES=core/db/factories/**/*{.ts,.js}\nTYPEORM_SEEDING_SEEDS=core/db/seeds/**/*{.ts,.js}\n```\n* Run the following command\n```java\nnpm run seed:config\n```\n* * Should Display the following Result\n```javascript\nTypeORM Seeding v1.6.1\n{\n  type: 'mysql',\n  host: 'localhost',\n  port: 3306,\n  username: 'root',\n  password: 'root',\n  database: 'klp',\n  entities: [\n    [class AlphaModel],\n    [class BetaModel extends AlphaModel],\n    [class Appoinment],\n    [class Book extends BetaModel],\n    [class Casez extends BetaModel],\n    [class City extends BetaModel],\n    [class Court extends BetaModel],\n    [class News extends BetaModel],\n    [class User extends AlphaModel],\n    [class Lawyer],\n    [class LawyerClient],\n    [class LawyerTeam],\n    [class Specialization extends BetaModel],\n    [class Task extends BetaModel],\n    [class LawyerCase extends BetaModel]\n  ],\n  retryDelay: 10000,\n  retryAttempts: 2,\n  logging: true,\n  synchronize: true,\n  dropSchema: true,\n  baseDirectory: 'D:\\\\Programming\\\\NEST_Best_Practice',\n  factories: [ 'src/database/factories/**/*{.ts,.js}' ],\n  seeds: [ 'src/database/seeds/**/*{.ts,.js}' ]\n}\n```\n### CUSTOM META DECORATOR\n* Create a Decorator\n* * [auth.decorator.ts](src/auth/auth.decorator.ts)\n* How to Check the Meta Atached by the Decorator in the Guard\n* * [auth.decorator.ts](src/auth/guard/auth.guard.ts)\n* Configure the Guard as the provide in any Module\n* * [auth.module.ts](src/auth/auth.module.ts)\n```java\n{\n  // This could be set in any module\n  provide: APP_GUARD,\n  useClass: JwtAuthGuard,\n},\n```\n* Set the Decorator on the Controller End point\n* * [auth.controller.ts](src/auth/auth.controller.ts)\n```java\n@Post('sign-in')\n// @UseGuards(LocalAuthGuard)\n@Public()\nsignIn(@Request() req, @Body() body: SignInDto) {\n  return this._ss.validateUser(body);\n}\n```\n### SEND EMAIL USING SENDGRID\n```javascript\n// using Twilio SendGrid's v3 Node.js Library\n// https://github.com/sendgrid/sendgrid-nodejs\njavascript\nconst sgMail = require('@sendgrid/mail')\nsgMail.setApiKey(ENV.SENDGRID_API_KEY)\nconst msg = {\n  to: 'test@example.com', // Change to your recipient\n  from: 'test@example.com', // Change to your verified sender\n  subject: 'Sending with SendGrid is Fun',\n  text: 'and easy to do anywhere, even with Node.js',\n  html: '\u003cstrong\u003eand easy to do anywhere, even with Node.js\u003c/strong\u003e',\n}\nsgMail\n  .send(msg)\n  .then(() =\u003e {\n    console.log('Email sent')\n  })\n  .catch((error) =\u003e {\n    console.error(error)\n  })\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahsansoftengineer%2Fnest_best_practice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahsansoftengineer%2Fnest_best_practice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahsansoftengineer%2Fnest_best_practice/lists"}