fastify
Version:
Fast and low overhead web framework, for Node.js
78 lines (65 loc) • 2.4 kB
Markdown
<h1 align="center">Fastify</h1>
<a name="server"></a>
`fastify.server`: The Node core [server](https://nodejs.org/api/http.html#http_class_http_server) object
<a name="ready"></a>
Function called when all the plugins has been loaded.
It takes an error parameter if something went wrong.
```js
fastify.ready(err => {
if (err) throw err
})
```
<a name="listen"></a>
Starts the server on the given port after all the plugins are loaded, internally waits for the `.ready()` event. The callback is the same as the Node core.
```js
fastify.listen(3000, err => {
if (err) throw err
})
```
<a name="route"></a>
Method to add routes to the server, it also have shorthands functions, check [here](https://github.com/fastify/fastify/blob/master/docs/Routes.md).
<a name="routes-iterator"></a>
The Fastify instance is an Iterable object with all the registered routes.
The route properties are the same the developer has declared [here](https://github.com/fastify/fastify/blob/master/docs/Routes.md).
```js
fastify.get('/route', opts, handler)
for (var route of fastify) {
console.log(route)
/* will output:
{
'/route': {
get: {
method: String,
ulr: String,
schema: Object,
handler: Function,
Request: Function,
Reply: Function
}
}
}
*/
}
```
<a name="close"></a>
`fastify.close(callback)`: call this function to close the server instance and run the [`'onClose'`](https://github.com/fastify/fastify/blob/master/docs/Hooks.md#on-close) hook.
<a name="decorate"></a>
Function useful if you need to decorate the fastify instance, Reply or Request, check [here](https://github.com/fastify/fastify/blob/master/docs/Decorators.md).
<a name="register"></a>
Fastify allows the user to extend its functionalities with plugins.
A plugin can be a set of routes, a server decorator or whatever, check [here](https://github.com/fastify/fastify/blob/master/docs/Plugins.md).
<a name="use"></a>
Function to add middlewares to Fastify, check [here](https://github.com/fastify/fastify/blob/master/docs/Middlewares.md).
<a name="addHook"></a>
Function to add a specific hook in the lifecycle of Fastify, check [here](https://github.com/fastify/fastify/blob/master/docs/Hooks.md).