avanelli / fastify-realworld-example-app

Fastify + Knex.js - Realworld Example App

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RealWorld Example App

JavaScript Style Guide

Fastify + Knex.js codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.

This codebase was created to demonstrate a fully fledged fullstack application built with Fastify + Knex.js including CRUD operations, authentication, routing, pagination, and more.

We've gone to great lengths to adhere to the Fastify + Knex.js community styleguides & best practices.

For more information on how to this works with other frontends/backends, head over to the RealWorld repo.

How it works

Knex and Data

The codebase makes use of in memory Sqlite3 database accessed via Knex.js

You can find migrations and seeds in /knex folder

All the database logics are in /models folder

Fastify and Routes

The Fastify server is setup in /server.js file.

It automatically loads all the routes from /routes folder and plugins from /plugins folder using @fastify-autoload plugin.

All routes and plugins are wrappeed inside a fastify-plugin

Getting started

Install dependencies and create .env file copying .env.example. You can customize it.

npm install
npm create:env

Run api server

npm start

You can also start the server in developer mode with autoreload and better logs (nodemon and pino-pretty).

npm run dev

Running API tests locally

To locally run the provided Postman collection against your backend, execute:

APIURL=http://localhost:5000/api ./run-api-tests.sh

You can also run TAP tests

npm test

EXTRA

There is an additional endpoint to get the sentiment score of a text.

curl -d '{"content":"You have done an excellent job. Well done!"}' -H "Content-Type: application/json" -X POST http://localhost:5000/api/sentiment/score

Contributing

If you find a bug please submit an Issue and, if you are willing, a Pull Request.

If you want to suggest a different best practice, style or project structure please open an issue explaining how we can improve this project.

We need your help to make this project better and keep it up to date!

License

MIT

About

Fastify + Knex.js - Realworld Example App

License:MIT License


Languages

Language:JavaScript 99.1%Language:Shell 0.9%