Skip to content

Commit

Permalink
docs(first-step): add missing code sample to run the app
Browse files Browse the repository at this point in the history
Closes #35
  • Loading branch information
Sorikairox committed Aug 14, 2022
1 parent 8ff42e0 commit 2d536f6
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions doc/first-steps/controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,29 @@ export class AppModule {}

We attached the metadata to the module class using the `@Module()` decorator,
and Danet can now easily reflect which controllers have to be mounted.

Now, it is time to create a DanetApplication that bootstrap our AppModule.

We advise you to create a bootstrap function that returns your DanetApplication instance, this will make testing easier as you can get your application instance and make it listen to a random port.

```ts bootstrap.ts
import { AppModule } from './app.module.ts';
import { DanetApplication } from 'https://deno.land/x/danet/mod.ts';

export const bootstrap = async () => {
const application = new DanetApplication();
await application.init(AppModule);
return application;
}
```
Run this function to get an application instance, and call `listen` method to run the server.
```ts run.ts
import { bootstrap } from './bootstrap.ts';

const application = await bootstrap();
await application.listen(Number(Deno.env.get('PORT') || 3000));
```
And finally execute this file with `deno run --allow-net --unstable --allow-env run.ts`

0 comments on commit 2d536f6

Please sign in to comment.