Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/peterdee/fastify-generic
Generic Fastify project
https://github.com/peterdee/fastify-generic
apidoc docker fastify javascript joi jsdoc mongodb node node-test-runner redis
Last synced: about 18 hours ago
JSON representation
Generic Fastify project
- Host: GitHub
- URL: https://github.com/peterdee/fastify-generic
- Owner: peterdee
- License: mit
- Created: 2023-11-30T13:50:32.000Z (about 1 year ago)
- Default Branch: release
- Last Pushed: 2024-02-05T18:50:01.000Z (12 months ago)
- Last Synced: 2024-11-20T14:51:00.494Z (2 months ago)
- Topics: apidoc, docker, fastify, javascript, joi, jsdoc, mongodb, node, node-test-runner, redis
- Language: JavaScript
- Homepage: http://localhost:9999
- Size: 272 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
## fastify-generic
Generic Fastify project with API documentation, API testing, authorization, database connection, Redis caching, etc.
Some of the code is typed with [JSDoc](https://jsdoc.app), but types are not enforced (not using `@ts-check` directive)
### Deploy locally
```shell script
git clone https://github.com/peterdee/fastify-generic
cd ./fastify-generic
nvm use 20
npm ci
```### Environment variables
The `.env` file is required, see [.env.example](.env.example) for details
### Launching the server
##### Without Docker container
Launch in `development` with hot reloading:
```shell script
npm run dev
```Launch in `production`:
```shell script
npm start
```Server will be available at http://localhost:9999 (port `9999` is a default one, you can change it in `.env` file)
##### With Docker container
*Make sure that application uses port `9999`!*
Build an image:
```shell script
docker build -t fastify-generic .
```Run container:
```shell script
docker run -p 9999:9999 -d fastify-generic
```Server will be available at http://localhost:9999
### API documentation
API documentation is generated using [apiDoc](https://www.npmjs.com/package/apidoc)
In order to generate documentation, `apiDoc` should be installed globally:
```shell script
npm i -g apidoc
```Generate documentation:
```shell script
npm run docs
```Documentation will be available at [http://localhost:9999/docs/](http://localhost:9999/docs/) once you start the server, however it will be served only if `APP_ENV` environment variable is set to `development`
### Testing
Tests are done with [`node:assert`](https://nodejs.org/api/assert.html) and [`node:test`](https://nodejs.org/api/test.html)
Tests are using [`mongodb-memory-server`](https://www.npmjs.com/package/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:
```shell script
npm run test
```It is possible to run a specific test (for example just a single controller test):
```shell script
export APP_ENV=testing && node --test ./apis/me/controller.test.js
```### Linting
Using [ESLint](https://eslint.org)
### License
[MIT](./LICENSE.md)