配置
// app.module.ts
import { Module } from '@nestjs/common';
import { AppService } from './app.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Users } from './users/users.entity';
import { UsersModule } from './users/users.module';
import { ArticleModule } from './article/article.module';
@Module({
imports: [
TypeOrmModule.forRoot({
type: 'mysql',
host: 'localhost',
port: 3306,
username: 'root',
password: '密码',
database: 'db',
entities: [__dirname + '/**/*.entity{.ts,.js}'],
synchronize: true,
}),
UsersModule,
ArticleModule,
],
providers: [AppService],
})
export class AppModule {}
一些常用命令
nest g co xxx // 创建controller
nest g mo xxx // 创建module
nest g s xxx // 创建service文件