Node.js API server/backend based on fastify and MongoDB as a database for persisting data, GitHub Actions build and code linter, minimal tooling and native node test runner with native coverage. Can be used as a template to quickly bootstrap your Node.js API HTTP server project.
- automatic reloading using fastify-cli
- native ESM module (ECMAScript) with imports/exports
- automatically generated swagger API documentation from models using fastify-swagger andfastify-swagger-ui
- load .env into the environment and validate it using fastify-env and dotenv
- linting and fixing using neostandard
- git pre-commit hooks using husky
- integration tests with node test runner
- API client Bruno
- coverage report using native node coverage
- continuous integration using GitHub Actions CI
- code coverage tracking using coveralls
- dependency update notifications using dependabot
- dependency merging using GitHub Action Merge Dependabot
- authoring of release notes using release-drafter
- code linting with MegaLinter
These instructions will help you get a copy of the project up and running on your local machine for development and testing.
git clone git@github.com:mihaur/node-fastify-template.git
cd node-fastify-template
cp .env.example .env
npm install
npm start
Use .env to store your environment-dependent configuration options and secrets; this file should not be checked into your repository. Use .env.example as an example but exclude real secrets.
The server accepts two environment variables:
FASTIFY_PORT
– listening port. It defaults to3000
and must be an integer.MONGODB_URI
– MongoDB connection string. This variable is required and must not be empty.
The application exposes interactive API documentation using Swagger UI.
Once the server is running, visit: http://localhost:3000/api/docs
Linting is done using neostandard. Use npm run lint
to run the linter. You can also automatically fix linter errors by running npm run lint:fix
.
Unit tests are located in src/component/__test/component.test.js. They are executed by the Node test runner using npm run test:unit
.
Integration tests are located in test/**.test.js. They are executed by the Node test runner using npm run test
.
Bruno serves as the API client testing tool, with its configuration stored in the bruno/
directory. Run the server in a separate terminal and execute API client tests, use the command npm run bruno
to run all tests, or npm run bruno -- ping
to run just ping collection.
Use npm run coverage
to show coverage in the console, or npm run coverage:lcov
to generate an lcov report.