Hey, this is a simple API!
You will need NodeJs
and Npm installed.
Before installing, a usefull tool to manage node versions would be nvm.
A database is also needed. In this project i am using MySql, but any other database can work with minor modifications.
Finaly, you might want to use a Virtual Environment to manage you development servers, databases and installations, to avoid polluting you native machine. Hosting different versions of stuff, on top of having various projects, can be hard to manage. Check out Vagrant.
Install node packages:
npm install
Please create a .env
file to the root folder, and configure it as follows, according to your database.
DATABASE_URL="mysql://events_api_user:password@localhost/events_api"
JWT_SECRET="cookies"
This project uses a JSON-like language to make schemas for the database. The Prisma ORM will also take care of migrations and other cool stuff. To get started:
npx prisma db push
npx prisma migrate dev
npx prisma generate
To run the application in dev mode:
npm run dev
You can check the server at
http://localhost:3001/
or visit the docs/client here http://localhost:3001/api-docs/.
Note:
While trying to authenticate with your JWT using Swagger client, you may encounter CORS errors! Unlilkely, but still, here is another browser addon 😄
Instead of installing a database management program like MYSQL Workbench, Prisma provides us with one. It is simple but cool. To access it run
npx prisma studio
To debug your API check out this cool API client for VSCode or use insomnia.
nvm
nvm for windows
NodeJs
Npm
Vagrant
MAMP server, windows
Prisma
express.js
typescript docs
Finish the implementation.
Add unit testing.
Finish the Swagger docs
Currently implemented for Swagger:
- User Creation
- JWT authentication
- event creation (if you make the same one twice server dies :))
- event deletion
Not cool:
- it has too many leftover schemas and stuff
Create a seed script for the db.
Install TsDoc to document the codebase.
Add a Vagrantfile of an instance that runs a suitable Node environment, turn project into a kind of monorepo.
Add a changelog.md file to keep track of changes.
Additional things that could be refined:
-
Code in Middlewares and handlers repeats itself, should be turned into functions/methods.
-
Swagger can automatically generate Docs by parsing comments on the code, with package "swagger-jsdoc".
Keep in mind, that would not be optimal if code is documentated with TSDoc, and would need further consideration.