TypeError: server.connection is not a function in Hapi nodejs

In hapi 16, there was support for server.connection(), but in hapi 17, they replaced server.connection() and instead

const Hapi = require('hapi')
const server = Hapi.server({
port:3000 || process.env.port
})

This can be used in node js.

If you are using typescript and typings, then

const server = new Hapi.server({port:3000 || process.env.port})

replace with this

const server = new Hapi.Server({  
  host: 'localhost',
  port: 3000
})

if you are using this

server.connection({   

    port: 8000,
    host: 'localhost'

});

I found a solution to resolve my error. I just replaced
server.connection({ port: 3000, host: 'localhost' });
with
const server = new Hapi.Server({ port: 3000, host: 'localhost' });

Here is the description below: According to hapi v17.0.0 they Removed support for multiple connections for a single server

  1. The server.connection() method is replaced with options passed directly when creating a server object.
  2. connection property is removed from all objects.
  3. All connection methods moved to the server.
  4. Removed support for labels and select() methods and options.

Tags:

Node.Js

Hapijs