Install Fastify
npm install fastifyInstall typescript
npm install -D typescript
npm install -D @types/nodeTo run the server, we need to convert the TS file to JS with the command line below:
npx tsc src/server.tsNow after the JS file is created, we can send the node to execute the JS file:
node src/server.jsTo make the TS file conversion process more efficient and run node on the converted file, we will install a tool called TSX. But we must remember that this tool is only for "development mode".
npm install tsx -Dnpx tsx src/server.tsnpm run devWe will use the query builder Knex.js for the database. https://knexjs.org
npm install knex sqlite3To create a migration:
npm run knex -- migrate:make create-documentsEnvironment variables: Install DotENV
npm install dotenvwe will use the ZOD lib for data validation in our environment variables
npm install zodTest whit Vitest https://vitest.dev
npm install vitest -DFor testing, the interesting thing is not to "raise a server", but for the agent to be able to make requests. To do this we will install the supertest library.
npm install supertest -D
npm install -D @types/supertestnpm run test