New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

create-fastify-app

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-fastify-app

A Fastify application generator

  • 1.5.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
26
decreased by-16.13%
Maintainers
1
Weekly downloads
 
Created
Source

create-fastify-app

js-standard-style Coverage Status Build Status Greenkeeper badge npm-version

Create Fastify App is an utility that help you to generate or add plugin to your Fastify project. This mean that you can easily:

  • Generate a Fastify Project, also from a given swagger file.
  • Generate a service skeleton in existing Fastify Project.
  • Add fastify-cors plugin in existing Fastify Project.
  • Add fastify-mongodb plugin in existing Fastify Project.
  • Add fastify-redis plugin in existing Fastify Project.
  • Add fastify-postgres plugin in existing Fastify Project.

Install

If you want to use create-fastify-app you must first install globally on your machine

npm install -g create-fastify-app

Usage

Generate Fastify projects and utilities:

  create-fastify-app [command] <options>

Command
  generate:project     Generate a ready to use Fastify project
  generate:service     Generate service skeleton source in given project
  add:mysql            Add fastify-mysql plugin in given project folder
  add:mongo            Add fastify-mongodb plugin in given project folder
  add:cors             Add fastify-cors plugin in given project folder
  add:redis            Add fastify-redis plugin in given project folder
  add:postgres         Add fastify-postgres plugin in given project folder

Options

  -d, --directory
      Fastify project folder

  -h, --help
      Show this help message

Except for generate:project command the others work on an existent project created with create-fastify-app.

generate:project

Generate a new Fastify project run following command

create-fastify-app generate:project -d <project-folder>

If -d, or --directory, option is omitted the new project will be created in curret folder. At this point further information will be asked:

  • Application Name: the application name.
  • Description: a short description non how the application do.
  • Author: the application author.
  • Email: the application email author.
  • Version: semver version.
  • Keywords: a list of comma separated keywords.
  • License: the application license.
  • Swagger File: a swagger file to start from (YAML or JSON).

After providing these information the entire application skeleton will be created for you. Simply run

cd /your/wonderful/application
npm install
npm run dev
Project structure

By default create-fastify-app generate a project structured in this way:

/your/wonderful/application
├── README.md
├── app
│   ├── app.js
│   ├── plugins
│   │   ├── README.md
│   │   └── support.js
│   └── services
│       ├── README.md
│       ├── hello
│       │   └── index.js
│       └── root.js
├── args.js
├── help
│   └── start.txt
├── package.json
├── server.js
└── test
    ├── helper.js
    ├── plugins
    │   └── support.test.js
    └── services
        ├── example.test.js
        └── root.test.js

The app folder contains all you need to develop your application. In particular, she contains the following directories:

  • plugins: here you can add all your plugins you need into you application.
  • 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.
  • test: here you can declare all your test.

The package.json file comes with three predefined npm task:

"scripts": {
  "test": "tap test/**/*.test.js",
  "start": "node server.js",
  "dev": "node server.js -l info -P"
}
  • npm test: runs the test
  • npm start: start your application
  • npm run dev: start your application with pino-colada pretty logging
Options

You can pass the following options via command line with node server.js <options>. Every options has the corresponding environment variable:

DescriptionShort commandFull commandEnvironment variable
The application file to start-f--fileFASTIFY_FILE
Port to listen on (default to 3000)-p--portFASTIFY_PORT or PORT
Address to listen on-a--addressFASTIFY_ADDRESS
Log level (default to fatal)-l--log-levelFASTIFY_LOG_LEVEL
Prints pretty logs-P--pretty-logsFASTIFY_PRETTY_LOGS
Use custom options-o--optionsFASTIFY_OPTIONS
Set the prefix-r--prefixFASTIFY_PREFIX
Set the plugin timeout-T--plugin-timeoutFASTIFY_PLUGIN_TIMEOUT
Defines the maximum payload, in bytes,
the server is allowed to accept
--body-limitFASTIFY_BODY_LIMIT
Generate a project from a swagger file

When 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 create-fastify-app will generate all your project endpoints for you. You will only have to worry about the development of the various endpoints.

If you give in input the Petstore swagger file given as example on Swagger.io, you can see that create-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:

swagger-example

In your app/services folder you'll find your endpoints folder

./app/services
├── README.md
├── pet
│   ├── index.js
│   └── routes.schema.js
├── root.js
├── store
│   ├── index.js
│   └── routes.schema.js
└── user
    ├── index.js
    └── routes.schema.js

generate:service

This command allow you to generate a new service skeleton for your api. You simply run

create-fastify-app generate:service -d <project-folder>

And give some information such as:

  • Service Name: The name of the service you want to generate
  • Methods to implement: GET, POST, PUT, DELETE etc.
  • Api Prefix: The prefix url (for example /api)

Moreover the command generate for you a small set of test foreach methods.

add:mongo

If you want to easily add the fastify-mongodb plugin to your application this command is all you need. Just simply run

create-fastify-app add:mongo -d <project-folder>

And give some information such as:

  • MongoDB Host: your MongoDB host.
  • MongoDB Port: your MongoDB port.
  • MongoDB Collection: your default collection.
  • MongoDB User: your MongoDB user.
  • MongoDB Password: your MongoDB password.

At this point the command add the fastify-mongodb to you application with the given information for your MongoDB connection.

add:mysql

If you want to easily add the fastify-mysql plugin to your application this command is all you need. Just simply run

create-fastify-app add:mysql -d <project-folder>

And give some information such as:

  • MySQL Host: your MySQL host.
  • MySQL Port: your MySQL port.
  • MySQL Database: your default database.
  • MySQL User: your MySQL user.
  • Mysql Password: your MySQL password.

At this point the command add the fastify-mysql to you application with the given information for your MySQL connection.

add:redis

If you want to easily add the fastify-redis plugin just simply run

create-fastify-app add:redis -d <project-folder>

And give some information such as:

  • Redis Host: your redis host
  • Redis Port: your redis port
  • Redis Password: your redis password, if you have one.
  • Redis Index: your redis index

exactly 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 connection.

add:cors

If you want to easily add the fastify-cors plugin just simply run

create-fastify-app add:cors -d <project-folder>

And give some information such as:

  • Method: at least one of DELETE, PATCH, POST, PUT, HEAD, OPTIONS

after the choises fastify-cors plugin will be added in your application.

add:postgres

If you want to easily add the fastify-postgres plugin to your application this command is all you need. Just simply run

create-fastify-app add:postgres -d <project-folder>

And give some information such as:

  • Postgres Host: your Postgres host.
  • Postgres Port: your Postgres port.
  • Postgres Database: your default database.
  • Postgres User: your Postgres user.
  • Postgres Password: your Postgres password.

At this point the command add the fastify-postgres to you application with the given information for your Postgres connection.

Contributing

If 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.

The code follows the Standard code style.

js-standard-style

Acknowledgements

It is inspired by the fastify-cli project. Some part have been extracted from it.

This project is kindly sponsored by Webeetle s.r.l.

License

Licensed under MIT.

Keywords

FAQs

Package last updated on 26 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc