database.module.ts
nest.js/03-advanced/code/database/database.module.ts
import { Module } from '@nestjs/common';
@Module({
providers: [
{
provide: 'DATABASE_CONNECTION',
useFactory: async () => {
// In a real application, this would create a database connection
// For this tutorial, we'll simulate it
console.log('Database connection established');
return {
type: 'postgres',
host: 'localhost',
port: 5432,
connected: true,
};
},
},
],
exports: ['DATABASE_CONNECTION'],
})
export class DatabaseModule {}
Articles liés
app.controller.ts
app.controller.ts — typescript source code from the nest.js learning materials (nest.js/01-beginner/code/app.controller.ts).
Lire l'article →app.module.ts
app.module.ts — typescript source code from the nest.js learning materials (nest.js/01-beginner/code/app.module.ts).
Lire l'article →app.service.ts
app.service.ts — typescript source code from the nest.js learning materials (nest.js/01-beginner/code/app.service.ts).
Lire l'article →main.ts
main.ts — typescript source code from the nest.js learning materials (nest.js/01-beginner/code/main.ts).
Lire l'article →todos.controller.ts
todos.controller.ts — typescript source code from the nest.js learning materials (nest.js/01-beginner/code/todos/todos.controller.ts).
Lire l'article →todos.module.ts
todos.module.ts — typescript source code from the nest.js learning materials (nest.js/01-beginner/code/todos/todos.module.ts).
Lire l'article →