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
- 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
- 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.
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
.
Use npm run coverage
to show coverage in the console, or npm run coverage:lcov
to generate an lcov report.