DEV Community

Cover image for fastify typeScript generator: a generator for creating fastify server with typescript
open devs
open devs

Posted on

fastify typeScript generator: a generator for creating fastify server with typescript

hi everyone, 👋
today we’ll learn to use a great generator tool to create a fastify server in everyone’s favourite typescript language. 👨‍💻

now the first question first, what is fastify?

https://fastify.io/

if you are coming from Node.js background you must have heard of expressjs, it is a web application framework that provides you with a simple API to build websites, web apps and back ends. Now express can be considered as a bit slower. fastify is detailed as a “fast and low overhead web framework, for Node.js”. fastify is a web framework highly focused on speed and low overhead. it is inspired by express and hapi, it is one of the fastest web frameworks in town. using fastify can increase your throughput by up to 100%.

advantages of using fastify?

  • 100% asynchronous: all the core is implemented with asynchronous code, in this way not even a millisecond is wasted.
  • highly performant: as far as we know, fastify is one of the fastest web frameworks in town, depending on the code complexity we can serve up to 20000 requests per second.
  • extendible: fastify is fully extensible via its hooks, plugins, and decorators.

https://fastify.io/benchmarks/

why do we need a generator?

to scaffold applications quicker we need a generator to provide us with a basic useful template on which we can expand based on our requirements.

& so comes fastify-typescript-generator

https://npmjs.com/package/fastify-typescript-generator

we created this generator keeping few things in mind:

  • using typescript in our templates for better coding standards & attain all the other benefits of typescript.
  • providing a template for people familiar with express
  • providing a template for people wanting to familiarize themselves with the concept of fastify and it’s the plugin system.
  • providing templates with the option to choose between mongoose (a well known MongoDB driver in node.js world supporting schema) & TypeORM which is an ORM that can be used to connect to various SQL as well as MongoDB database (MongoDB connection in BETA) & work with them built specifically keeping typescript in mind.
  • some templates have OpenAPI (previously Swagger) implementation
  • a cool interactive CLI

so please check it out. it’s already gaining tracking in the community.

npm

https://www.npmjs.com/package/fastify-typescript-generator

how to use it?

https://github.com/open-devs/fastify-typescript-generator#-demo

or in textual form:

install

npm i -g fastify-typescript-generator
Enter fullscreen mode Exit fullscreen mode

usage

run anyone of following commands:

fastify-gen
# or
fastify-typescript-generator
# or
fastify-ts-gen
Enter fullscreen mode Exit fullscreen mode

who are we?

we are open devs an organization of two motivated developers (@alok722, @mikr13) building open source tools & software to contribute to the community. we are very welcoming towards collaboration & new people joining us in any capacity with a vision to profit community in terms of great tools and education.
you can join us in various places:
npm
github
twitter
website

Top comments (6)

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

You forgot the link to the repo.

I am a Fastify fan. The real reason I am using Fastify is not speed, but built-in validation that can be extended to OpenAPI.

Also, your Twitter links to the wrong website.

Collapse
 
opendevsorg profile image
open devs

apologies and we are very thankful to you for pointing the mistakes, we are just getting started and learning fastify too but with enough confidence, we felt like fastify needs a good boilerplate creation tool. That was the actual motivation & the point you mentioned is also really something awesome about fastify.

Collapse
 
alok722 profile image
Alok Raj

seeing the response on npm from the community, super pumped up to work on the future releases. ✌

Collapse
 
agamm profile image
Agam

Why not use npx? also, prisma would be nice :)

Collapse
 
opendevsorg profile image
open devs

Thank you for mentioning about npx, we have defined this already on GitHub repository readme. Furthermore, Prisma is definitely nice but every other package has its own advantages.

Collapse
 
slidenerd profile image
slidenerd

The official generator can also generate typescript github.com/fastify/fastify-cli why not use it?

Some comments may only be visible to logged-in visitors. Sign in to view all comments.