radiorz
radiorz

Reputation: 1889

why is so differult between the app generated by fastify-cli and the example in the documentation?

where is the start.js in the project which is generated by fastify-cli ?

i think its big different between the getting start example and the app generated by fastify-cli?

should i write the start function like this in the project created by fastify-cli?

const start = async () => {
  try {
    await sequelize.sync({})
    app.log.info('database sync correctly')
    await app.listen(PORT, '0.0.0.0')
    app.swagger()
  } catch (err) {
    app.log.error(err)
    process.exit(1)
  }
}
start()

there are just a app.js in the project generated by fastify-cli.what a different!

Upvotes: 3

Views: 1335

Answers (1)

Manuel Spigolon
Manuel Spigolon

Reputation: 12900

where is the start.js in the project which is generated by fastify-cli ?

There is not, it is replaced by the CLI utility fastify your-file.js in the package.json (like mocha, jest etc.. does to run tests) Usually the starter file is always the same, so it has been integrated in the cli and you can use the args to set the PORT or to reload the server automatically when you edit one file.

i think its big different between the getting start example and the app generated by fastify-cli?

The docs teach all you need to know about the framework, the plugins and utility around it want to ease the developer experience.. like manage a mongodb-connectio: it is one line with the official plugin.

should i write the start function like this in the project created by fastify-cli?

If you use fastify my-file.js you don't need it. After some experience you will understand when you need the fastify-cli or not. I think the cli is useful in the most use cases and it suggests good ways to implement configurations loading and encapsulation. You won't need it for special use cases that need to run some async operation before the server is created

Upvotes: 3

Related Questions