← All tools

fastify-cli

Popularity 65 Updated Development & Build

Run a fastify route with one command!

npmauto-collected

Installation

npm
npm install -g fastify-cli

Install with npm.

fastify-cli

Command line tools for Fastify. Generate, write, and run an application with one single command!

Install

npm install fastify-cli --global

Usage

fastify-cli offers a single command line interface for your Fastify project:

$ fastify

Which will print a help message:

Fastify command line interface, available commands are:

  * start                 start a server
  * eject                 turns your application into a standalone executable with a server.(js|ts) file being added
  * generate              generate a new project
  * generate-plugin       generate a new plugin project
  * generate-swagger      generate Swagger/OpenAPI schema for a project using @fastify/swagger
  * readme                generate a README.md for the plugin
  * print-routes          prints the representation of the internal radix tree used by the router, useful for debugging.
  * print-plugins         prints the representation of the internal plugin tree used by avvio, useful for debugging.
  * version               the current fastify-cli version
  * help                  help about commands

Launch 'fastify help [command]' to know more about the commands.

The default command is start, you can hit

fastify start plugin.js

to start plugin.js.


### start

You can start any Fastify plugin with:

$ fastify start plugin.js


A plugin can be as simple as:

// plugin.js module.exports = function (fastify, options, next) { fastify.get('/', function (req, reply) { reply.send({ hello: 'world' }) }) next() }


If you are using Node 8+, you can use `Promises` or `async` functions too: