Mubasshir Pawle
Mubasshir Pawle

Reputation: 319

need help to identify issue

Following is my snippet of main.ts

  try {
    process.on('unhandledRejection', (err) => {
      // tslint:disable-next-line:no-console
      console.error(err); <------- no console
    });
    const app = await NestFactory.create<NestFastifyApplication>(
      AppModule,
      new FastifyAdapter(),
    );
    app.enableCors();
    app.useGlobalFilters(new AllExceptionsFilter());

    await app.listen(3000, () => {
      // tslint:disable-next-line:no-console
      console.log('listen callback'); <------- no console
    }).then(() => {
      // tslint:disable-next-line:no-console
      console.log('started'); <------- no console
    });
  } catch (error) {
    // tslint:disable-next-line:no-console
    console.log('catch', error); <----- only this gets consoled as undefined
  }

My app gets connected to database (verified), just that it doesn't start.

Upvotes: 0

Views: 62

Answers (1)

nerdy beast
nerdy beast

Reputation: 789

Calling .listen() with a callback argument means this method is going to return undefined. You are trying to call .then() on that undefined value.

You need simply need to change your listen call to this:

await app.listen(3000, () => 'Server running on port 3000...');

BONUS: You can test this yourself by setting that call to listen to a variable and then console log it:

const result = await app.listen(3000, () => 'Server running on port 3000...');

console.log(result);
//undefined

Upvotes: 1

Related Questions