Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Spoke with @capjamesg about this before. And I had some time to give this a go now 😊
Fastify responds to more than 2× the requests in the same time as Express. Making it a better choice on servers where resources are shared with other applications. (There are even more optimised frameworks, but they will often be a developer experience downgrade, lack other things, or opt to completely replace Node.js’ HTTP code with their own C++ implementation.) For ease and stability, I chose to stick to Fastify rather than go more bleeding edge.
With that said, Fastify has gotten many more updates than Express. The latest releases are from 2023-07-27 and 2022-10-08 respectively. So while you may always be hearing about Express, that is really not the most up-to-date framework to start on anymore.
The other reason why I brought up moving away from Express was that other frameworks, like Fastify, have gotten a lot better at handling promise rejections. Rather than crashing when something throws, it will return an HTTP 500 by default. Much how you might be used to coming from PHP.
This PR does the following (and supersedes #21):
Because of the code flattening, I recommend looking at the diff ignoring whitespace changes. That will make it easier to spot the actual logic changes vs just flattening.
Because this PR is also for others to learn a little about Fastify, here is what changed coming from Express (I might miss something):
info
level) for everything that previously used the locallog()
function. Thedebug_log
setting variable is still used and can be set to false to disable all log output coming from Fastify.express.static()
.nun_env.*
code needed changing.).view()
on the response object, rather than.render()
of Express. This ends up being a simple find and replace..view()
has been made toreturn
. This also ensures that there is never an instance where it is tried to render responses twice. (Flattening the promises also helps to make sure that there is never an asynchronous process still running that might try to respond.).listen()
is changed to follow the new syntax.A lot of these changes are simple find and replaces. A Codemod could have probably done it all.
Please have a look, and let me know if you would consider merging this, whether there are any questions, or if you would rather continue with Express. (In the case of the latter, #21 is not superseded and could still be worth merging 😉 )