Hapi and TypeScript— splitting routes into multiple files

Paul Walker
JavaScript in Plain English
3 min readMar 12, 2021

--

Last time we left it, the server only had a single route and was all in one file. That’s fine to start with but it’s not exactly scalable. Let’s add some routes from external files.

We’ll go for something similar to the traditional “hello world”. We’ll have a route, /hello, which will say “Hello World”. We’ll also add a route “under” that, /hello/name, which will greet name.

The files we produce here are all in the GitHub repo.

Test it!

--

--

Software engineer in Bristol, UK. Playing around in my spare time with Nodejs, Typescript, Elixir and Phoenix, Vue and more.