TypeError: reply is not a function

Version 17 of Hapi has a quite different API.

https://hapijs.com/api/17.1.0

Route handlers are no longer passed the reply function as the second argument, instead they are passed something called the Response Toolkit which is an object containing properties and utilities for taking care of the response.
With the new API you don't even have to use the Response Toolkit to return a simple text response as in your case, you can simply return the text from the handler:

//add the route
server.route({
  method: 'GET',
  path: '/helloworld',
  handler: function (request, h) {
    return 'hello world';
  }
});

The Response Toolkit is used to customize the response, such as setting the content type. Ex:

  ...
  handler: function (request, h) {
    const response = h.response('hello world');
    response.type('text/plain');
    return response;
  }

Note: with this new API, server.start() doesn't take a callback function and if you provide one anyway it won't get invoked (you may have noticed that the console.log() in your callback function never happen). Now, server.start() returns a Promise instead which can be used to verify that the server started properly.

I believe this new API is designed to be used with async-await syntax.


To solve this problem you just need to replace return reply('hello world'); with return 'hello world'; Here is the description below:

According to hapi v17.x they Replaced the reply() interface with a new lifecycle methods interface:

  1. removed response.hold() and response.resume().

  2. methods are async and the required return value is the response.

  3. a response toolkit (h) is provided with helpers (instead of the reply() decorations).