If you had to list the characteristics of the perfect Node.js web application framework, you’d probably come up with something like this:
import(...)
for more granular manual controlNext.js is close to this ideal. If you haven’t encountered it yet, I strongly recommend going through the tutorials at learnnextjs.com. Next introduced a brilliant idea: all the pages of your app are files in a your-project/pages
directory, and each of those files is just a React component.
Everything else flows from that breakthrough design decision. Finding the code responsible for a given page is easy, because you can just look at the filesystem rather than playing ‘guess the component name’. Project structure bikeshedding is a thing of the past. And the combination of SSR (server-side rendering) and code-splitting — something the React Router team gave up on, declaring ‘Godspeed those who attempt the server-rendered, code-split apps’ — is trivial.
But it’s not perfect. As churlish as it might be to list the flaws in something so, so good, there are some:
/blog/hello-world
instead of /post?slug=hello-world
). This undermines the guarantee about directory structure corresponding to app structure, and forces you to maintain configuration that translates between the two formsserver.js
file to handle these cases, but it feels at odds with the declarative approach taken for pages<a>
tags. Instead, you have to use framework-specific <Link>
components, which is impossible in the markdown content for a blog post such as this one, for example#web