Skip to content

ligerzero459/fastify-template-mongo

Repository files navigation

fastify-template-mongo

Fastify HTTP server template with a MongoDB connection managed through Mongoose.

Prerequisites

  • Node.js and npm
  • Docker with Docker Compose support

Install dependencies

npm install

Start the Docker services

This project ships with Docker Compose files that start MongoDB and mongo-express for local development.

npm run start

Services exposed locally:

  • MongoDB: mongodb://admin:password@localhost:27017/default?authSource=admin
  • mongo-express: http://localhost:8081

To stop the containers and remove local volumes created by the stack:

npm run stop

Start the web server

The app reads local environment variables from env/local.env and starts Fastify on port 3000.

npm run start:dev

Once started, the API is available at http://localhost:3000.

Routes

Root

  • GET /
  • Returns a simple confirmation message that the Fastify server is running.

Heartbeat

  • GET /heartbeat
  • Liveness-style endpoint for confirming that the web server process is up.
  • Expected response: 200 OK

Health

  • GET /health
  • Health-style endpoint that reports application status and current MongoDB connection state.
  • Returns 200 OK when MongoDB is connected and 503 when the app is up but the database is not healthy.

Project references

About

Template repo for basic fastify webserver with MongoDB connection using Mongoose

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors