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 replacedserver.connection({ port: 3000, host: 'localhost' });
withconst 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
- The server.connection() method is replaced with options passed directly when creating a server object.
- connection property is removed from all objects.
- All connection methods moved to the server.
- Removed support for labels and select() methods and options.