文件结构:
├── README.md ├── nest-cli.json ├── package.json ├── src │ ├── user │ │ ├── Entity │ │ ├── Interface │ │ ├── Dto │ │ ├── app.controller.ts │ │ ├── app.module.ts │ │ └── app.service.ts │ ├── app.controller.spec.ts │ ├── app.controller.ts │ ├── app.module.ts │ ├── app.service.ts │ └── main.ts ├── test │ ├── app.e2e-spec.ts │ └── jest-e2e.json ├── tsconfig.build.json └── tsconfig.json
app controller 和 service 负责主页相关逻辑,新建模块如user 放入新的文件夹下,整体结构更加清晰。
设置模板引擎和指定目录:
async function bootstrap() {
const app:NestExpressApplication = await NestFactory.create(AppModule);
app.useStaticAssets(join(__dirname, '..', 'public'));
app.setBaseViewsDir(join(__dirname, '..', 'views'));
app.setViewEngine('ejs');
await app.listen(3000);
}www.haizhuan.tk