-
-
Notifications
You must be signed in to change notification settings - Fork 132
Unify the way of importing and initializing the app and other pieces #259
Comments
Only if the author decides to use ESM. ESM is not necessary and it is not promoted as the primary syntax -- see nodejs/node#33954. |
Totally agree with that @jsumners, that's also why the above examples/suggestions still include CommonJS' require. My thoughts behind this proposal were mostly related to the fact of unifying the import and initialization. Other than that: damn, a reply within 3 mins, that's not bad ^^ |
I agree to unify the docs and for CJS or ESM I saw a simple switch that shows the syntax chosen by the user (I cant remember which module) I would like to unity also the plugin instance arg:
or |
@Eomm what about renaming them to |
Personally, I think For this reason, I would like to think if there are better options |
I think |
I normally use the following everywhere: app.register(async function plugin (app, opts) {
}) |
For me, it will be all import Fastify from 'fastify'
const fastify = Fastify({ logger: true })
fastify.register(async function (fastify, options) {
//...
}) |
That is also a good choice. |
What plays towards |
100% agree! Furthermore, I'll be all in to always use ESM, and it will be the future of the language, so better adopt it sooner rather than later. Even if currently it does not offer all the features of CJS. Still, we should keep a CJS example somewhere.
I've always used
👍
Yes! Given this is a documentation there is no reason to save chars, let's go for the full name of every parameter, is more clear and welcoming with new users. |
So could I go with fastify? And if so, should the files also be called |
The files should not be called fastify as it would be ambiguous. |
File should be either Spliting |
I recommend using app.js as a factory and server.js as the entry point. |
I think this should be transferred either to fastify/fastify-snippet or to fastify/fastify |
🚀 Feature Proposal
I'd suggest three minor things to enhance the docs:
fastify
/server
toapp
throughout the docs.req
and sometimes it'srequest
)Motivation
Currently, there are different examples on how Fastify is being imported and how the app is being initialized (see below). Also, with the rise of ESM-Modules, imports mostly shift from something like
const Fastify = require('fastify')
toimport Fastify from 'fastify'
, which makes things, such asconst app = require('fastify')({ logger: true })
impossible. Also, it's less of a mind-shifting to use the same terms for the same thing (using the termapp
instead of usingfastify
orserver
for actually the same thing)Currently, these are the two variations:
JavaScript (shortened):
TypeScript (shortened):
Example
With this proposal, the above examples and all examples throughout the documentation would be unified in terms of how to name and initialize the app. Also, the example of directly importing and initializing the app in one step will be split up into an import and a separate initialization. This avoids varying terms like
fastify
andserver
for actually the same thing.JavaScript (shortened):
TypeScript (shortened):
The text was updated successfully, but these errors were encountered: