Generic Fastify project with API documentation, API testing, authorization, database connection, Redis caching, etc.
Some of the code is typed with JSDoc, but types are not enforced (not using @ts-check directive)
git clone https://github.com/peterdee/fastify-generic
cd ./fastify-generic
nvm use 20
npm ciThe .env file is required, see .env.example for details
Launch in development with hot reloading:
npm run devLaunch in production:
npm startServer will be available at http://localhost:9999 (port 9999 is a default one, you can change it in .env file)
Make sure that application uses port 9999!
Build an image:
docker build -t fastify-generic .Run container:
docker run -p 9999:9999 -d fastify-genericServer will be available at http://localhost:9999
API documentation is generated using apiDoc
In order to generate documentation, apiDoc should be installed globally:
npm i -g apidocGenerate documentation:
npm run docsDocumentation will be available at http://localhost:9999/docs/ once you start the server, however it will be served only if APP_ENV environment variable is set to development
Tests are done with node:assert and node:test
Tests are using mongodb-memory-server to emulate MongoDB connection, but there are no emulation for Redis (currently no modules are available for that): when tests are running, the app will try to connect to the Redis server specified by the REDIS_TEST_CONNECTION_STRING environment variable
Run all tests:
npm run testIt is possible to run a specific test (for example just a single controller test):
export APP_ENV=testing && node --test ./apis/me/controller.test.jsUsing ESLint