Nest: Binding IP for a nest application is verbose

Created on 31 Aug 2017  路  8Comments  路  Source: nestjs/nest

Hullo 馃憢

Currently if you want to bind your express instance to a specific IP you end up with something like this:

@Module({})
class ApplicationModule {}x

function createApp (
  server: express.Application,
  port: number,
  address: string
): Promise<INestApplication> {
  const app = NestFactory.create(ApplicationModule, server)
  app.init()

  return eventToPromise(server.listen(port, address), 'listening').then(
    () => app
  )
}

It would seem more ideal if NestApplication.listen() better reflected the options that ExpressAppliation.listen() takes? The above isn't so ideal given that it doesn't check if the nest application has already been initialised.

type

Most helpful comment

@TobyColeman environment variables?

All 8 comments

Hi @TobyColeman,
Definitely needed, marked as a todo.

@TobyColeman environment variables?

Hey ! You can use dotenv easily for that

Ah nice, I wasn't aware of an approach like this - https://stackoverflow.com/a/10714707 should have looked at the express docs a bit further. Cheers for noting that down @kamilmysliwiec!

@adrien2p could you show how?

I noticed this project at least presents a way to configure express directly:

https://github.com/d3viant0ne/nestjs-mongoose

Hi @TobyColeman,
Since @nestjs/core 4.0.4 the listen() method accepts hostname as a second argument :slightly_smiling_face:

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings