Skip to content

Node.js API server/backend based on fastify and MongoDB as a database for persisting data, GitHub Actions build and code linter, minimal tooling (neostandard), and native node test runner. Can be used as a template to quickly bootstrap your Node.js API http server project.

License

Notifications You must be signed in to change notification settings

mihaur/node-fastify-template

Repository files navigation

Node.js API server based on fastify + MongoDB project template

neostandard javascript style Conventional Commits GitHub Actions CI Coverage Status MegaLinter

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.

All features

Getting Started

These instructions will help you get a copy of the project up and running on your local machine for development and testing.

Prerequisites

Installing

  • git clone git@github.com:mihaur/node-fastify-template.git
  • cd node-fastify-template
  • cp .env.example .env
  • npm install
  • npm start

Configuring

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 to 3000 and must be an integer.
  • MONGODB_URI – MongoDB connection string. This variable is required and must not be empty.

API documentation

The application exposes interactive API documentation using Swagger UI.

Once the server is running, visit: http://localhost:3000/api/docs

Linting and code fixing

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

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

Integration tests are located in test/**.test.js. They are executed by the Node test runner using npm run test.

API client 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.

Coverage reports

Use npm run coverage to show coverage in the console, or npm run coverage:lcov to generate an lcov report.

About

Node.js API server/backend based on fastify and MongoDB as a database for persisting data, GitHub Actions build and code linter, minimal tooling (neostandard), and native node test runner. Can be used as a template to quickly bootstrap your Node.js API http server project.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •