Rucken Core NestJS 项目教程

Rucken Core NestJS 项目教程

core-nestjsA simple application demonstrating the basic usage of permissions with NestJS (JWT, Passport, Facebook, Google+, User, Group, Permission)项目地址:https://gitcode.com/gh_mirrors/co/core-nestjs

1. 项目的目录结构及介绍

rucken-core-nestjs/
├── src/
│   ├── app/
│   │   ├── auth/
│   │   ├── core/
│   │   ├── entities/
│   │   ├── modules/
│   │   ├── services/
│   │   └── app.module.ts
│   ├── config/
│   ├── migrations/
│   ├── seeders/
│   ├── shared/
│   ├── main.ts
│   └── ormconfig.json
├── test/
├── .env
├── .gitignore
├── package.json
├── tsconfig.json
└── README.md

目录结构介绍

  • src/: 项目的源代码目录。
    • app/: 包含应用程序的主要模块和功能。
      • auth/: 认证相关的代码。
      • core/: 核心功能模块。
      • entities/: 数据库实体定义。
      • modules/: 应用程序的模块。
      • services/: 服务层代码。
      • app.module.ts: 应用程序的主模块。
    • config/: 配置文件目录。
    • migrations/: 数据库迁移文件。
    • seeders/: 数据库种子文件。
    • shared/: 共享代码和工具函数。
    • main.ts: 应用程序的入口文件。
    • ormconfig.json: TypeORM 配置文件。
  • test/: 测试代码目录。
  • .env: 环境变量配置文件。
  • .gitignore: Git 忽略文件配置。
  • package.json: 项目依赖和脚本配置。
  • tsconfig.json: TypeScript 配置文件。
  • README.md: 项目说明文档。

2. 项目的启动文件介绍

main.ts

main.ts 是项目的入口文件,负责启动 NestJS 应用程序。以下是 main.ts 的主要内容:

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app/app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  await app.listen(3000);
}
bootstrap();

启动文件介绍

  • NestFactory.create(AppModule): 创建 NestJS 应用程序实例。
  • app.listen(3000): 启动应用程序并监听 3000 端口。

3. 项目的配置文件介绍

ormconfig.json

ormconfig.json 是 TypeORM 的配置文件,用于配置数据库连接。以下是 ormconfig.json 的主要内容:

{
  "type": "postgres",
  "host": "localhost",
  "port": 5432,
  "username": "your_username",
  "password": "your_password",
  "database": "your_database",
  "synchronize": true,
  "logging": false,
  "entities": ["src/app/entities/**/*.ts"],
  "migrations": ["src/migrations/**/*.ts"],
  "subscribers": ["src/subscribers/**/*.ts"],
  "cli": {
    "entitiesDir": "src/app/entities",
    "migrationsDir": "src/migrations",
    "subscribersDir": "src/subscribers"
  }
}

配置文件介绍

  • type: 数据库类型(例如:postgres, mysql, sqlite 等)。
  • host: 数据库主机地址。
  • port: 数据库端口。
  • username: 数据库用户名。
  • password: 数据库密码。
  • database: 数据库名称。
  • synchronize: 是否自动同步数据库结构。
  • logging: 是否启用日志记录。
  • entities: 数据库实体文件路径。
  • migrations: 数据库迁移文件路径。
  • subscribers: 数据库订阅者文件路径。
  • cli: CLI 工具的配置。

.env

.env 文件用于存储环境变量,例如数据库连接信息、API 密钥等。以下是 .env 文件的示例内容:

DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=your_username
DB_PASSWORD=your_password
DB_DATABASE=your_database

环境变量介绍

  • DB_HOST: 数据库主机地址。
  • DB_PORT: 数据库端口。
  • DB_USERNAME: 数据库用户名。
  • DB_PASSWORD: 数据库密码。
  • DB_DATABASE: 数据库名称。

通过这些配置文件,可以灵活地配置和管理项目的运行环境和数据库连接。

core-nestjsA simple application demonstrating the basic usage of permissions with NestJS (JWT, Passport, Facebook, Google+, User, Group, Permission)项目地址:https://gitcode.com/gh_mirrors/co/core-nestjs

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

明咏耿Helena

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值