{"id":13403738,"url":"https://github.com/davidedantonio/create-fastify-app","last_synced_at":"2025-10-03T01:31:28.043Z","repository":{"id":34300203,"uuid":"168822858","full_name":"davidedantonio/create-fastify-app","owner":"davidedantonio","description":"An utility that help you to generate or add plugin to your Fastify project","archived":true,"fork":false,"pushed_at":"2022-04-10T02:48:13.000Z","size":7666,"stargazers_count":53,"open_issues_count":39,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-15T14:22:00.883Z","etag":null,"topics":["art-template","cors","dockerize","ejs","fastify","fastify-plugin","fastify-swagger","handlebars","marko","mongodb","nodejs","nodejs-library","postgres","redis","scaffolding","skeleton-application","swagger"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidedantonio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-02T11:00:52.000Z","updated_at":"2024-08-15T15:37:03.000Z","dependencies_parsed_at":"2022-08-08T00:15:47.151Z","dependency_job_id":null,"html_url":"https://github.com/davidedantonio/create-fastify-app","commit_stats":null,"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidedantonio%2Fcreate-fastify-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidedantonio%2Fcreate-fastify-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidedantonio%2Fcreate-fastify-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidedantonio%2Fcreate-fastify-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidedantonio","download_url":"https://codeload.github.com/davidedantonio/create-fastify-app/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235059234,"owners_count":18929279,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["art-template","cors","dockerize","ejs","fastify","fastify-plugin","fastify-swagger","handlebars","marko","mongodb","nodejs","nodejs-library","postgres","redis","scaffolding","skeleton-application","swagger"],"created_at":"2024-07-30T19:01:33.920Z","updated_at":"2025-10-03T01:31:22.687Z","avatar_url":"https://github.com/davidedantonio.png","language":"JavaScript","readme":"# create-fastify-app\n\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) [![Coverage Status](https://coveralls.io/repos/github/davidedantonio/create-fastify-app/badge.svg?branch=master)](https://coveralls.io/github/davidedantonio/create-fastify-app?branch=master) [![Build Status](https://travis-ci.com/davidedantonio/create-fastify-app.svg?branch=master)](https://travis-ci.com/davidedantonio/create-fastify-app) [![Known Vulnerabilities](https://snyk.io/test/github/davidedantonio/create-fastify-app/badge.svg)](https://snyk.io/test/github/davidedantonio/create-fastify-app) ![npm-version](https://img.shields.io/npm/v/create-fastify-app.svg)\n\nCreate Fastify App is an utility that help you to generate or add plugin to your [Fastify](https://github.com/fastify/fastify) project. This mean that you can easily:\n\n- Generate a Fastify Project, also from a given swagger file.\n- Generate a service skeleton in existing Fastify Project.\n- Add fastify-cors plugin in existing Fastify Project.\n- Add fastify-mongodb plugin in existing Fastify Project.\n- Add fastify-redis plugin in existing Fastify Project.\n- Add fastify-postgres plugin in existing Fastify Project.\n- Add point-of-view plugin in existing Fastify Project.\n\n## Install\n\nIf you want to use `fastify-app` you must first install globally on your machine\n\n```\nnpm install -g create-fastify-app\n```\n\n## Enable autocompletion\n\nrun the following command from your terminal. Pay attention to the `. ./` or the autocompletion feature won't start.\n\n```\n. ./cfa-autocompletion.sh\n```\n\n## Usage\n\n```\nGenerate Fastify projects and utilities:\n\n  fastify-app [command] \u003coptions\u003e\n\nCommand\n  generate:project     Generate a ready to use Fastify project\n  generate:service     Generate service skeleton source in given project\n  add:mysql            Add fastify-mysql plugin in given project folder\n  add:mongo            Add fastify-mongodb plugin in given project folder\n  add:cors             Add fastify-cors plugin in given project folder\n  add:redis            Add fastify-redis plugin in given project folder\n  add:postgres         Add fastify-postgres plugin in given project folder\n  add:pov              Add Point-Of-View plugin in given project folder\n\nOptions\n\n  -d, --directory\n      Fastify project folder\n\n  -h, --help\n      Show this help message\n```\n\nExcept for `generate:project` command the others work on an existent project created with `fastify-app`.\n\n### `generate:project`\n\nGenerate a new Fastify project run following command\n\n```\nfastify-app generate:project -d \u003cproject-folder\u003e\n```\n\nIf `-d`, or `--directory`, option is omitted the new project will be created in curret folder. At this point further information will be asked:\n\n- **Application Name**: the application name.\n- **Description**: a short description non how the application do.\n- **Author**: the application author.\n- **Email**: the application email author.\n- **Version**: semver version.\n- **Keywords**: a list of comma separated keywords.\n- **License**: the application license.\n- **Swagger File**: a swagger file to start from (YAML or JSON).\n\nAfter providing these information the entire application skeleton will be created for you. Simply run\n\n```\ncd /your/wonderful/application\nnpm install\nnpm run dev\n```\n\n#### Project structure\n\nBy default `fastify-app` generate a project structured in this way:\n\n```\n/your/wonderful/application\n├── docker-compose.yml\n├── Dockerfile\n├── help\n│   └── start.txt\n├── package.json\n├── README.md\n├── src\n│   ├── hooks\n│   │   ├── onError.js\n│   │   ├── onRequest.js\n│   │   ├── onResponse.js\n│   │   ├── onSend.js\n│   │   ├── preHandler.js\n│   │   ├── preParsing.js\n│   │   ├── preSerialization.js\n│   │   └── preValidation.js\n│   ├── index.js\n│   ├── plugins\n│   │   ├── README.md\n│   │   └── support.js\n│   └── services\n│       ├── hello\n│       │   └── index.js\n│       ├── README.md\n│       └── root.js\n└── test\n    ├── helper.js\n    ├── plugins\n    │   └── support.test.js\n    └── services\n        ├── example.test.js\n        └── root.test.js\n```\n\nThe `src` folder contains all you need to develop your application. In particular, she contains the following directories:\n\n- `plugins`: here you can add all your plugins you need into you application.\n- `services`: here you can develop all the endpoint you need for your application, or the generated endpoint if you give a swagger file at project creation.\n- `hooks`: here you can declare all the hooks you need for your fastify application.\n\nThe `package.json` file comes with three predefined npm task:\n\n```diff\n\"scripts\": {\n  \"test\": \"tap test/**/*.test.js\",\n  \"start\": \"fastify-app run\",\n  \"dev\": \"fastify-app run -l info -P -w\"\n}\n```\n\n* `npm test`: runs the test\n* `npm start`: start your application\n* `npm run dev`: start your application with [`pino-colada`](https://github.com/lrlna/pino-colada) pretty logging and in watching mode\n\nThe `Dockerfile` and the `docker-compose.yml` files allow you to dockerize your application. When you add a plugin, for example with `add:mongo`, the `docker-compose.yml` will automatically updated with given information. Here the `Dockerfile` generated:\n\n```\nFROM node:latest\nRUN mkdir -p /usr/src/app\nWORKDIR /usr/src/app\nCOPY package.json /usr/src/app/\nRUN npm install\nCOPY . /usr/src/app\nEXPOSE 3000\nCMD [ \"npm\", \"install\", \"-g\", \"create-fastify-app\" ]\nCMD [ “npm”, \"start\" ]\n```\n\nand the `docker-compose.yml`:\n\n```\nversion: '3.7'\nservices:\n  fastify-app:\n    container_name: fastify-app\n    restart: always\n    build: .\n    image: fastify-app:1.0.0\n    ports:\n      - '3000:3000'\n    expose:\n      - '3000'\n```\n\n#### Options\n\nYou can pass the following options via command line with `fastify run \u003coptions\u003e`. Every options has the corresponding environment variable:\n\n|  Description | Short command | Full command | Environment variable |\n| ------------- | ------------- |-------------| ----- |\n| The application file to start | `-f` | `--file` | `FASTIFY_FILE` |\n| Port to listen on (default to 3000) | `-p` | `--port` | `FASTIFY_PORT or PORT` |\n| Address to listen on | `-a` | `--address` | `FASTIFY_ADDRESS` |\n| Log level (default to fatal) | `-l` | `--log-level` | `FASTIFY_LOG_LEVEL` |\n| Prints pretty logs | `-P` | `--pretty-logs` | `FASTIFY_PRETTY_LOGS` |\n| Use custom options | `-o` | `--options` | `FASTIFY_OPTIONS` |\n| Set the prefix | `-r` | `--prefix` | `FASTIFY_PREFIX` |\n| Set the plugin timeout | `-T` | `--plugin-timeout` | `FASTIFY_PLUGIN_TIMEOUT` |\n| Defines the maximum payload, in bytes,\u003cbr\u003ethe server is allowed to accept |  | `--body-limit` | `FASTIFY_BODY_LIMIT` |\n| Start the application in watching mode on your file changes | `-w` | `--watch` | |\n\n#### Generate a project from a swagger file\n\nWhen you generate a new project you can give in input a swagger file. In an api driven project this feature can be very important because `fastify-app` will generate all your project endpoints for you. You will only have to worry about the development of the various endpoints.\n\nIf you give in input the [Petstore](https://editor.swagger.io/?_ga=2.5251579.932457202.1552732701-831465500.1549699944) swagger file given as example on [Swagger.io](https://swagger.io), you can see that `fastify-app` automatically generate a project with `fastify-swagger` already configured and ready to use in your project. If you take a look at `/documentation` endpoint you'll find something like that:\n\n![swagger-example](./images/swagger.png)\n\nIn your `src/services` folder you'll find your endpoints folder\n\n```\n./src/services\n├── README.md\n├── pet\n│   ├── index.js\n│   └── routes.schema.js\n├── root.js\n├── store\n│   ├── index.js\n│   └── routes.schema.js\n└── user\n    ├── index.js\n    └── routes.schema.js\n```\n\n### `generate:service`\n\nThis command allow you to generate a new service skeleton for your api. You simply run\n\n```\nfastify-app generate:service -d \u003cproject-folder\u003e\n```\n\nAnd give some information such as:\n\n- **Service Name**: The name of the service you want to generate\n- **Methods to implement**: GET, POST, PUT, DELETE etc.\n- **Api Prefix**: The prefix url (for example `/api`)\n\nMoreover the command generate for you a small set of test foreach methods.\n\n### `add:mongo`\n\nIf you want to easily add the [`fastify-mongodb`](https://github.com/fastify/fastify-mongodb) plugin to your application this command is all you need. Just simply run\n\n```\nfastify-app add:mongo -d \u003cproject-folder\u003e\n```\n\nAnd give some information such as:\n\n- **MongoDB Host**: your MongoDB host.\n- **MongoDB Port**: your MongoDB port.\n- **MongoDB Collection**: your default collection.\n- **MongoDB User**: your MongoDB user.\n- **MongoDB Password**: your MongoDB password.\n\nAt this point the command add the `fastify-mongodb` to you application with the given information for your [MongoDB](https://www.mongodb.com) connection.\n\n### `add:mysql`\n\nIf you want to easily add the [`fastify-mysql`](https://github.com/fastify/fastify-mysql) plugin to your application this command is all you need. Just simply run\n\n```\nfastify-app add:mysql -d \u003cproject-folder\u003e\n```\n\nAnd give some information such as:\n\n- **MySQL Host**: your MySQL host.\n- **MySQL Port**: your MySQL port.\n- **MySQL Database**: your default database.\n- **MySQL User**: your MySQL user.\n- **Mysql Password**: your MySQL password.\n\nAt this point the command add the `fastify-mysql` to you application with the given information for your [MySQL](https://www.mysql.com) connection.\n\n### `add:redis`\n\nIf you want to easily add the [`fastify-redis`](https://github.com/fastify/fastify-redis) plugin just simply run\n\n```\nfastify-app add:redis -d \u003cproject-folder\u003e\n```\n\nAnd give some information such as:\n\n- **Redis Host**: your redis host\n- **Redis Port**: your redis port\n- **Redis Password**: your redis password, if you have one.\n- **Redis Index**: your redis index\n\nexactly as the `add:mongo` and `add:mysql` command `add:redis` add the plugin into your application plugins folder with the given information for your [Redis](https://redis.io) connection.\n\n### `add:cors`\n\nIf you want to easily add the [`fastify-cors`](https://github.com/fastify/fastify-cors) plugin just simply run\n\n```\nfastify-app add:cors -d \u003cproject-folder\u003e\n```\n\nAnd give some information such as:\n\n- **Method**: at least one of DELETE, PATCH, POST, PUT, HEAD, OPTIONS\n\nafter the choises `fastify-cors` plugin will be added in your application.\n\n### `add:postgres`\n\nIf you want to easily add the [`fastify-postgres`](https://github.com/fastify/fastify-postgres) plugin to your application this command is all you need. Just simply run\n\n```\nfastify-app add:postgres -d \u003cproject-folder\u003e\n```\n\nAnd give some information such as:\n\n- **Postgres Host**: your Postgres host.\n- **Postgres Port**: your Postgres port.\n- **Postgres Database**: your default database.\n- **Postgres User**: your Postgres user.\n- **Postgres Password**: your Postgres password.\n\nAt this point the command add the `fastify-postgres` to you application with the given information for your [Postgres](https://www.postgresql.org/) connection.\n\n### `add:pov`\n\nThis option add [`point-of-view`](https://github.com/fastify/point-of-view) plugin to you fastify project. `point-of-view` decorates the reply interface with the view method for manage view engines that can be used to render templates responses. You can decide to install one of the following template engines:\n\n- ejs\n- ejs-mate\n- nunjucks\n- pug\n- handlebars\n- marko\n- mustache\n- art-template\n\nJust simply run\n\n```\nfastify-app add:pov -d \u003cproject-folder\u003e\n```\n\n## Eject your application\n\n**Note: this is a one-way operation. Once you eject, you can’t go back!**\n\nIf you aren’t satisfied with the build tool and configuration choices, you can eject at any time. This command will remove the `fastify-app` dependency from your code.\n\nTo do this you can run\n\n```\nfastify-app eject\n```\n\nfrom your application root. This command will copy all the files that `fastify-app` use to run your application (the watch module for example). All the command, except the `eject` obviously, will still work, but they will point to the copied script in your root folder, and yes you can hack them.\n\nSo when you eject your application your project structure is something like this:\n\n```\n├── args\n│   └── run.js\n├── docker-compose.yml\n├── Dockerfile\n├── help\n│   └── start.txt\n├── lib\n│   └── watch\n│       ├── constants.js\n│       ├── fork.js\n│       ├── index.js\n│       └── utils.js\n├── package.json\n├── README.md\n├── run.js\n├── src\n│   ├── hooks\n│   │   ├── onError.js\n│   │   ├── onRequest.js\n│   │   ├── onResponse.js\n│   │   ├── onSend.js\n│   │   ├── preHandler.js\n│   │   ├── preParsing.js\n│   │   ├── preSerialization.js\n│   │   └── preValidation.js\n│   ├── index.js\n│   ├── plugins\n│   │   ├── README.md\n│   │   └── support.js\n│   └── services\n│       ├── hello\n│       │   └── index.js\n│       ├── README.md\n│       └── root.js\n└── test\n    ├── helper.js\n    ├── plugins\n    │   └── support.test.js\n    └── services\n        ├── example.test.js\n        └── root.test.js\n```\n\nYour script package json now have many more dependencies, and the `start` and `dev` scripts looks like the following lines:\n\n```\n\"scripts\": {\n  \"test\": \"tap test/**/*.test.js\",\n  \"start\": \"node run.js\",\n  \"dev\": \"node run.js -l info -P -w\"\n}\n```\n\n## Contributing\n\nIf you feel you can help in any way, be it with examples, extra testing, or new features please open a pull request or open an issue.\n\nThe code follows the Standard code style.\n\n[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n\n### Running Tests\n\nThe version `2.0` comes with a `docker-compose.yml` with all the necessary to run tests. Simply install [docker](https://docs.docker.com/install/) and [docker-compose](https://docs.docker.com/compose/install/) and run `docker-compose up -d`. After do that simply run `npm run test`.\n\n## Acknowledgements\n\nIt is inspired by the [fastify-cli](https://github.com/fastify/fastify-cli) project. Some part have been extracted from it.\n\nThis project is kindly sponsored by [Webeetle s.r.l.](https://www.webeetle.com)\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidedantonio%2Fcreate-fastify-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidedantonio%2Fcreate-fastify-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidedantonio%2Fcreate-fastify-app/lists"}