Some description of project
npm install
So copy the .env.example
to .env
and configure envroiment variables.
npm run test
Build
docker build -t napd-fastify .
Running
docker run -p 3000:3000 -e DEV=1 -v $(pwd):/app -t napd-fastify
Build
docker build -t napd-fastify .
Running
docker run -p 3000:3000 -t napd-fastify
├── src
│ ├── app.js
│ ├── config
│ │ ├── mongodb.js
│ │ ├── sentry.js
│ │ └── swagger.js
│ ├── plugins
│ │ ├── README.md
│ │ ├── responseApi.js
│ │ └── sentry.js
│ ├── server.js
│ ├── services
│ │ ├── lightningCount.js
│ │ ├── lightning.js
│ │ ├── README.md
│ │ └── root.js
│ └── utils
│ └── generatorResponse.js
└── test
├── helper.js
├── plugins
│ ├── responseApi.test.js
│ └── sentry.test.js
├── services
│ ├── lightning.test.js
│ └── root.test.js
└── util
└── date.js
Every base configuration is exported there, is an adapter between environment variables for JS.
Fastify allows the user to extend its functionalities with plugins.
A plugin can be a set of routes, a server decorator or whatever. The API that you will need to use one or more plugins, is register
.
By default, register
creates a new scope, this means that if you do some changes to the Fastify instance (via decorate
), this change will not be reflected to the current context ancestors, but only to its sons. This feature allows us to achieve plugin encapsulation and inheritance, in this way we create a direct acyclic graph (DAG) and we will not have issues caused by cross dependencies.
You already see in the getting started section how using this API is pretty straightforward.
fastify.register(plugin, [options])
Services define routes within your application. Fastify provides an easy path to a microservice architecture, in the future you might want to independently deploy some of those.
In this folder you should define all the services that define the routes
of your web application.
Each service is a Fastify
plugin, it is
encapsulated (it can have its own independent plugins) and it is
typically stored in a file; be careful to group your routes logically,
e.g. all /users
routes in a users.js
file. We have added
a root.js
file for you with a '/' root added.
If a single file become too large, create a folder and add a index.js
file there:
this file must be a Fastify plugin, and it will be loaded automatically
by the application. You can now add as many files as you want inside that folder.
In this way you can create complex services within a single monolith,
and eventually extract them.
If you need to share functionality between services, place that
functionality into the plugins
folder, and share it via
decorators.
- dotenv: Loads environment variables from .env file
- fastify: Fast and low overhead web framework, for Node.js
- fastify-autoload: Require all plugins in a directory
- fastify-helmet: Important security headers for Fastify
- fastify-plugin: Plugin helper for Fastify
- fastify-swagger: Generate Swagger files automatically for Fastify.
- eslint-config-standard: JavaScript Standard Style - ESLint Shareable Config
- eslint-plugin-import: Import with sanity.
- eslint-plugin-node: Additional ESLint's rules for Node.js
- eslint-plugin-promise: Enforce best practices for JavaScript promises
- eslint-plugin-standard: ESlint Plugin for the Standard Linter
- nodemon: Simple monitor script for use during development of a node.js app.
- pre-commit: Automatically install pre-commit hooks for your npm modules.
- simple-get: Simplest way to make http get requests. Supports HTTPS, redirects, gzip/deflate, streams in < 100 lines.
- standard: JavaScript Standard Style
- tap: A Test-Anything-Protocol library
MIT